Game Development Reference
In-Depth Information
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 im-
ages 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 us-
ing the
SKTexture
object to create the sprite in place of the preceding method used to
create a sprite:
1. Create the
SKTexture
object with the same image of the spaceship:
SKTexture* spaceShipTexture = [SKTexture
textureWithImageNamed:@"Spaceship.png"];
2. Use the preceding texture object to create the
SKSpriteNode
object:
self.spaceShipSprite = [SKSpriteNode
spriteNodeWithTexture:spaceShipTexture];
3. Then, follow the same steps to add the sprite to the
FSMyScene
file making the
snippet look like this:
Now, as memory management is more optimized with texture, we can start with the anima-
tions to change the frames of a sprite by a fixed time. For that, we will be showing a prop
in the environment, which is a coin rotating 360 degrees horizontally.
The following are the steps involved to make a coin look like it is rotating 360 degrees ho-
rizontally: