Game Development Reference
In-Depth Information
@end
We have thus created a property to hold the user's state of touch on the paddle.
6. Now we will implement touchesBegan:withEvent function in our
GameScene.m file. Add the following function just next to the init method:
-(void)touchesBegan:(NSSet*)touches
withEvent:(UIEvent*)event {
UITouch* touch = [touches anyObject];
CGPoint touchLocation = [touch
locationInNode:self];
SKPhysicsBody* body = [self.physicsWorld
bodyAtPoint:touchLocation];
if (body && [body.node.name isEqualToString:
paddleCategoryName]) {
NSLog(@"touch began on paddle");
self.isPaddleTapped = YES;
}
}
This function will listen for the touch begin event and use it to find the body at
the location where the user taps on the scene. In the next line, we get the physics
body at the touch location.
7. Now compile and run the code. When you touch on the paddle, you should be
able to see the logs demonstrating the touch working on the paddle.
8. Now let us go ahead and implement touchesMoved:withEvent and add the
following function just next to touchesBegan :
Search WWH ::




Custom Search