Game Development Reference
Listing 5-9. GameLayer Receives the Remaining Touch Events and Uses Them to Scroll
[[CCDirector sharedDirector].touchDispatcher addTargetedDelegate:self
-(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.
// Always swallow touches, GameLayer is the last layer to receive touches.
-(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