Book Image

iOS Game Programming Cookbook

Book Image

iOS Game Programming Cookbook

Overview of this book

Table of Contents (19 chapters)
iOS Game Programming Cookbook
Credits
About the Authors
About the Reviewers
www.PacktPub.com
Preface
Index

Animating your textures


In this recipe, we will look at how textures are created and attached to sprites. We will also do some content change (that is, frame changing animations) with the help of textures.

Getting ready

To get started with textures to be animated, we should know about scenes, nodes, and sprites. As sprites are created with an image and are added on scene, which occupies more memory, textures should be a solution to this problem.

How to do it...

As the images are stored in App Bundle, the simplest way to create a sprite with texture is to create the texture first and then the sprite using the same texture. At runtime, the images are loaded from the app bundle to become the texture and then the visible entity called sprite.

So in the previous chapter, we created the sprite using its class method:

  self.spaceShipSprite = [SKSpriteNode spriteNodeWithImageNamed:@"Spaceship.png"];

Now, we will continue with the final solution kit created in the previous chapter thereby using the SKTexture...