Game Development Reference
In-Depth Information
// Move the game layer back to its designated position.
CCMoveTo* move = [CCMoveTo actionWithDuration:1 position:gameLayerPosition];
CCEaseIn* ease = [CCEaseIn actionWithAction:move rate:0.5f];
ease.tag = ActionTagGameLayerMovesBack;
[self runAction:ease];
}
Because GameLayer is the last layer to receive input, it doesn't need to do any
isTouchForMe checks and simply swallows all touches.
Tip Instead of handling user input in multiple layers, consider having one layer
dedicated to all input handling. It can decide what to do, forward touches to
other layers, and call methods on other nodes. The advantage of this is shorter
and less error-prone input handling code, because all the decisions are made in
one class instead of being spread out to a variety of classes.
The ccTouchMoved event calculates the difference between the previous and current
touch location. It's then reversed by multiplying it by −1 to change the effect from
moving the camera over the background to moving the background under the camera.
If you have a hard time imagining what I mean by that, try the ScenesAndLayers02
project and then try it a second time, commenting out the moveTo =
ccpMult(moveTo, -1); line. You'll notice the second time that every finger
movement moves the layer in the opposite direction.
ccTouchEnded simply moves the layer back to its center position automatically
when the user lifts the finger off the screen. Figure 5-2 shows this project in action with
the whole GameLayer rotated and zoomed out. Every game object on the GameLay-
er abides by every movement, rotation, and scaling of the GameLayer automatically,
whereas the UserInterfaceLayer always stays put.
 
Search Nedrilad ::




Custom Search