Game Development Reference
In-Depth Information
How it works...
When we create a texture object using SKTexture , as we did in the preceding section, the
texture stores the image (that is, frame) data into it which is further forwarded to create a
sprite. This helps in memory management, because when the sprites are removed, the data
associated with them (that is, texture) is also removed thereby releasing the memory.
SKTexture* spaceShipTexture = [SKTexture
textureWithImageNamed:@"Spaceship.png"];
self.spaceShipSprite = [SKSpriteNode
spriteNodeWithTexture:spaceShipTexture];
Similarly, the coin is also added using texture in the center of the screen with its initial
frame, which looks like this:
Now we will see how animations of frames work using a number of textures. We have just
created some textures using some coin images, which are visually designed in increasing
order of horizontal rotation angle. So an array in the same order of textures is created.
NSArray *coinAnimationTextures =
@[coinInitialTexture,coin2Texture,coin3Texture,coin4Texture,coin5Texture,coin6Texture];
Using a class method of SKAction , the coin animation textures array is given as an input
with a frame delay of 0.2 seconds.
SKAction *coinAnimation = [SKAction
animateWithTextures:coinAnimationTexturestimePerFrame:0.2];
[coinSprite runAction:coinAnimation];
Search WWH ::




Custom Search