Game Development Reference
In-Depth Information
SKTexture* coin5Texture = [textureAtlas
textureNamed:@"Coin5.png"];
SKTexture* coin6Texture = [textureAtlas
textureNamed:@"Coin6.png"];
4. Once all the textures are created, use the same code of addCoin to add and an-
imate the coin.
5. Let's make the coin animation more live and natural. Feed the action formed for
animating the texture with a fixed delay to another SKAction making it repeat
forever giving a feel of continuous rotation of coin (never ending).
SKAction *rotateAction = [SKAction
animateWithTextures:coinAnimationTextures
timePerFrame:0.2];
SKAction *coinRepeatForeverAnimation = [SKAction
repeatActionForever:rotateAction];
[coinSprite runAction:coinRepeatForeverAnimation];
6. After a little tweaking, remove the last texture from the array so that when the
repeatForever action is going to run, the first image will appear after the last
image, so there is no need for the last texture.
NSArray *coinAnimationTextures =
@[coinInitialTexture,coin2Texture,coin3Texture,coin4Texture,coin5Texture,coin6Texture];
Now our forever rotating coin is built and can be used either as a prop or collectables in
our game.
These are the steps to make the coins collectables:
1. For making a coin move from the left end to the right end of the screen, we have
to calculate the initial and final positions.
CGFloat coinInitialPositionX =
self.frame.size.width + coinSprite.size.width/2;
CGFloat coinInitialPositionY = arc4random() % 320;
CGPoint coinInitialPosition =
CGPointMake(coinInitialPositionX,
Search WWH ::




Custom Search