Game Development Reference
In-Depth Information
// Access the GameLayer via MultiLayerScene.
GameLayer* gameLayer = [MultiLayerScene sharedLayer].gameLayer;
// Run Actions on GameLayer ... (code removed for clarity)
return isTouchHandled;
-(void) ccTouchEnded:(UITouch*)touch withEvent:(UIEvent *)event
CCNode* node = [self getChildByTag:UILayerTagFrameSprite];
NSAssert([node isKindOfClass:[CCSprite class]], @"node is not a CCSprite");
((CCSprite*)node).color = ccWHITE;
In registerWithTouchDispatcher , the UserInterfaceLayer registers it-
self as a targeted touch handler with a priority of −1. Because GameLayer uses the
same code but with a priority of 0, the UserInterfaceLayer is the first layer to
receive touch input.
In ccTouchBegan , the first thing to do is to check whether this touch is of relevance
to the UserInterfaceLayer . The isTouchForMe method implements a simple
“point in boundingBox” check via CGRectContainsPoint to see whether the
touch began on the uiframe sprite. More useful methods are available in CGGeo-
metry to test intersection, containing points, or equality. Refer to Apple's documenta-
tion to learn more about the CGGeometry methods ( ht-
icsImaging/Reference/CGGeometry/Reference/reference.html ) .
If the touch location check determines that the touch is on the sprite, ccTouchBegan
returns YES , signaling that this touch event was used and should not be processed by
other layers with a targeted touch delegate of lower priority.
Only if the isTouchForMe check fails will the GameLayer receive the touch input
and use it to scroll itself when the user moves a finger over the screen. You can com-
pare GameLayer 's input handling code in Listing 5-9 .
Search Nedrilad ::

Custom Search