Game Development Reference
In-Depth Information
How it works…
The most important part of this section is the collision detection. It is done with the help of
the CGRectIntersectsRect method in which the coins are enumerated and checked
whether their frames intersect the spaceship frame. If they do, then two different anima-
tions are played on the coin and spaceship.
[self enumerateChildNodesWithName:@"Coin"usingBlock:
^(SKNode *node, BOOL *stop)
{
if
(CGRectIntersectsRect(self.spaceShipSprite.frame,
node.frame))
{
}
}];
When detection happens, the game looks like this:
Now we come to animations. The animation of the spaceship is a simple one. Just to give a
feel of collecting the coins, scaleUp and scaleDown animations are used in sequence.
SKAction* scaleUp = [SKAction scaleTo:1.4 duration:0.2];
SKAction* scaleDown = [SKAction scaleTo:1.0
duration:0.2];
NSArray* scaleSequenceAnimations = [NSArray
arrayWithObjects:scaleUp, scaleDown, nil];
Search WWH ::




Custom Search