Game Development Reference
In-Depth Information
Listing 5-9. GameLayer Receives the Remaining Touch Events and Uses Them to Scroll
Itself
-(void) registerWithTouchDispatcher
{
[[CCDirector sharedDirector].touchDispatcher addTargetedDelegate:self
priority:0
swallowsTouches:YES];
}
-(BOOL) ccTouchBegan:(UITouch*)touch withEvent:(UIEvent *)event
{
lastTouchLocation = [MultiLayerScene locationFromTouch:touch];
// Stop the move action so it doesn't interfere with the user's scrolling.
[self stopActionByTag:ActionTagGameLayerMovesBack];
// Always swallow touches, GameLayer is the last layer to receive touches.
return YES;
}
-(void) ccTouchMoved:(UITouch*)touch withEvent:(UIEvent *)event
{
CGPoint currentTouchLocation = [MultiLayerScene locationFromTouch:touch];
// Take the difference of the current to the last touch location.
CGPoint moveTo = ccpSub(lastTouchLocation, currentTouchLocation);
// Then reverse to give the impression of moving the background
moveTo = ccpMult(moveTo, -1);
lastTouchLocation = currentTouchLocation;
// Adjust the layer's position accordingly, and with it all child nodes.
self.position = ccpAdd(self.position, moveTo);
}
-(void) ccTouchEnded:(UITouch*)touch withEvent:(UIEvent *)event
{
 
Search Nedrilad ::




Custom Search