Game Development Reference
In-Depth Information
CGRect targetRect = CGRectMake(self.target.x -
boxWidth, self.target.y - boxWidth, boxWidth*2,
boxWidth*2);
if (!CGRectContainsPoint(targetRect,
self.position)) {
[self arrive:self.target deltaTime:deltaTime];
}
}
The final update function should look something similar to the following screen-
shot:
3. Now, it's time to check the arrive function we have written in the Player.m file.
Open the GameScene.m file. Take the following line of code:
behaviourType = Flee;
Then, replace this with the following line of code:
behaviourType = Arrive;
4. Now, compile and run the project; you should see our player in the center of the
screen. Now, click anywhere on the screen to provide the target for the player.
After you have tapped, the player will arrive at the target location you have
Search WWH ::




Custom Search