Time for action – detecting and ignoring collisions
It is time to detect when the stone hits the hunter. When the stone collides with the hunter, the player will lose.
In addition to this, we're going to detect when the stone hits the ground. In this case, we're going to ignore the collision and let the stone fall through the ground. We need to do this to avoid a lot of stones lying on the ground and hurting the hunter's legs. Just joking, he has shoes, right? The real reason is that the large number of stones on the level will simply block our hunter at some point. Refer to the following steps:
- Open the
PhysicsHunter.m
file and in thecreatePhysicsBody
method, set thebody.collisionType
property to@"hunter"
, as shown in the following code:-(void)createPhysicsBody { //..skipped.. body.collisionType = @"hunter"; self.physicsBody = body; }
- Then, add the
die
method, which will be called when the stone hits the hunter, as shown in...