O'Reilly logo

iOS Game Development By Example by Samanyu Chopra

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Working with texture objects

When a sprite is created, Sprite Kit creates a texture also. But sometime we require texture to do some complex work, such as:

  • Changing the sprite
  • Animation
  • Using the same texture between multiple sprites
  • Rendering a node tree into a texture like a screen shot

To make this simple, Sprite Kit provides us the SKTexture class. We can make an object of this class and use it as we want.

Open your MenuScene.swift file and make a reference of SKTexture:

let testingTexture : SKTexture Now initialize it inside init code block init(size:CGSize, playbutton:String, background:String) { PlayButton = SKSpriteNode(imageNamed: playbutton) Background = SKSpriteNode(imageNamed: background) MyPlayButton = SKSpriteNode(imageNamed: playbutton) ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required