Game Development Reference
In-Depth Information
Lastly the sequence action formed runs on the spaceship.
[self.spaceShipSprite
runAction:spaceShipCollectingAnimation];
4. For the coin, the animation should be as if it is disappearing as it is taken by the
spaceship. Thus, two core animations
fadeOut
and
scaleDown
are created
with a 0.2 scale factor having a time interval of 0.4 each, forming an array of an-
imations.
- (void)runCollectedAnimationForCoin:(SKNode*)coinNode
{
SKAction* coinFadeOutAnimation = [SKAction
fadeOutWithDuration:0.4];
SKAction* scaleDownAnimation = [SKAction
scaleTo:0.2 duration:0.4];
NSArray* coinAnimations = [NSArray
arrayWithObjects:coinFadeOutAnimation,
scaleDownAnimation, nil];
}
5. Using these animations, a group animation is formed.
SKAction* coinGroupAnimation = [SKAction
group:coinAnimations];
6. As for the coin, when it collides with the spaceship, it has to be removed from the
scene when its animation is over. So create an action using the block to remove
the coin after the previously created group animation is completed.
SKAction* coinAnimationFinishedCallBack = [SKAction
customActionWithDuration:0.0 actionBlock:^(SKNode
*node,CGFloat elapsedTime)
{
[node removeFromParent];
}];
In the preceding code snippet, we are using the
removeFromParent
function,
which is similar to
removeFromSuperview
in UIKit.