Game Development Reference
In-Depth Information
for (UITouch *touch in touches) {
CGPoint location = [touch locationInNode:self];
NSLog(@"%@", NSStringFromCGPoint(location));
newplayer.target = location;
}
8. So, now we are all set for the seek behavior. So, finally, we will call the player's
update method on every update of the scene, so that the player can seek to the loc-
ation a user has tapped on. To perform this add the following code:
-(void)update:(CFTimeInterval)currentTime {
/* Called before each frame is rendered */
if (!CGPointEqualToPoint(newplayer.target,
CGPointZero)) {
float deltaTime = currentTime - lastTime;
[newplayer update:deltaTime];
lastTime = currentTime;
}
}
In the above line of code, we are calling the update function on each and every
newPlayer object.
9. Now, compile and run the project; you will see the player in the center of the
screen and it will seek the location that you will tap on the screen. The output
should look something similar to the following screenshot:
Search WWH ::




Custom Search