Game Development Reference
In-Depth Information
Speed: 100 with 100 range
Acceleration: X at 0 and Y at -50
Scale: 0.1 with 0.1 range and 1 speed
Rotation: At zero and blue color
This makes a nice yellow ball that looks dangerous enough for enemies and the blue
flame for power-ups. In order to use collisions and collision handling, we need to
change the masks in ERGPlayer.m and the old values to the following ones:
self.physicsBody.contactTestBitMask = shieldPowerupBitmask |
enemyBitmask;
self.physicsBody.collisionBitMask = groundBitmask;
self.physicsBody.categoryBitMask = playerBitmask;
Again, the preceding code should be straightforward. The first line sets masks that
we want to register contact events with. The second line sets automatic collisions
with the ground, we want these to work as they did before. And the final line is the
category to identify us.
Now we need to modify ERGMyScene.m and add methods to handle contacts:
- (void) didBeginContact:(SKPhysicsContact *)contact
{
ERGPlayer *player = nil;
if (contact.bodyA.categoryBitMask == playerBitmask) {
player = (ERGPlayer *) contact.bodyA.node;
if (contact.bodyB.categoryBitMask == shieldPowerupBitmask) {
player.shielded = YES;
contact.bodyB.node.hidden = YES;
}
if (contact.bodyB.categoryBitMask == enemyBitmask) {
[player takeDamage];
contact.bodyB.node.hidden = YES;
}
} else {
player = (ERGPlayer *) contact.bodyB.node;
if (contact.bodyA.categoryBitMask == shieldPowerupBitmask) {
player.shielded = YES;
contact.bodyA.node.hidden = YES;
}
if (contact.bodyA.categoryBitMask == enemyBitmask) {
[player takeDamage];
contact.bodyA.node.hidden = YES;
}
}
}
 
Search WWH ::




Custom Search