Implementing game play
It is now time to implement the game play in which, how the players (tanks) are going to win or lose in the game called TankRace will be determined. The game play is that, whichever player first reaches the finish line on their opposite side, of the same color as their own, wins the race and other loses.
Getting ready
Before we begin, we must know how to detect collision from sprites in the SpriteKit and a little about playing with the labels of SpriteKit. In this section, we will be implementing the game play and also show an alert when there is no connection between the devices.
How to do it
Following are the steps involved for implementing the game play and deciding who wins or loses:
- We will be detecting the collision in the update method of the
GameScene
by using a method calledCGRectIntersectsRect
. In this, we can pass the two frames of nodes and it will check if the two frames intersect with each other or not. With this check, we will only check this for local...