Game Development Reference
In-Depth Information
lows you to obtain high-pass (instantaneous) and low-pass (smooth) filtered ac-
celerometer values as properties, for example:
float smoothed = [KKInput sharedInput].acceleration.smoothedX;
Typically accelerometer-controlled games use a low-pass filter; low-pass
means filtering out sudden, extreme changes of acceleration and thereby
smoothing the resulting values. The following is a low-pass filter that generates
new smoothedX / smoothedY values (instance variables) from the accelero-
meter input values ( rawX / rawY ) and a constant fi lterFactor in the range
from 0.0 to 1.0. A good filter factor would be 0.1, which means only 10% of
the current raw acceleration values are factored into the new smoothed values:
smoothedX = (rawX * filterFactor) + (smoothedX * (1.0 - fil-
smoothedY = (rawY * filterFactor) + (smoothedY * (1.0 - fil-
Adding Obstacles
This game isn't any good until we add something for the player to avoid. Let's intro-
duce an abomination of nature: a six-legged man-spider. Who wouldn't want to avoid
As with the player sprite, you should add the spider.png and spider-hd.png
files to the Resources group. Then the GameLayer.h file gets three new member
variables added to its interface: a spiders NSMutableArray , whose class refer-
ence is shown in Listing 4-9 , and the spiderMoveDuration and numSpider-
sMoved , which are used in Listing 4-12 :
@interface GameLayer : CCLayer
CCSprite* player;
CGPoint playerVelocity;
Search Nedrilad ::

Custom Search