Game Development Reference
In-Depth Information
app with acceleration values. You tell it to activate accelerometer input and to set the
filtering factor in the init method of the DoodleDrop GameLayer class:
// Yes, we want to receive accelerometer input events.
[KKInput sharedInput].accelerometerActive = YES;
[KKInput sharedInput].acceleration.filteringFactor = 0.2f;
Enabling the accelerometer will first test whether the device supports the Core Motion
framework. If so, acceleration values will be provided by Core Motion, which gives us
a tiny performance benefit. In all other cases, the standard UIAccelerometer interface is
used to obtain acceleration values. The filtering factor is a percentage that determines
how responsive the game character will react to sudden changes in acceleration.
Listing 16-5 shows the modified DoodleDrop update method that includes user input
handling for both platforms.
Listing 16-5 . Handling User Input for Both Platforms with KKInput
-(void) update:(ccTime)delta
KKInput* input = [KKInput sharedInput];
if (isGameOver)
if (input.anyTouchEnded ||←
[input isKeyDown:kKKKeyCode_Space] ||←
[input isKeyDown:kKKKeyCode_Return])
[self resetGame];
[self acceleratePlayerWithX:input.acceleration.smoothedX];
if ([input isKeyDown:kKKKeyCode_LeftArrow])
[self acceleratePlayerWithX:-keyAcceleration];
else if ([input isKeyDown:kKKKeyCode_RightArrow])
Search Nedrilad ::

Custom Search