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

Adding a sprite without using textures

Mostly in a game, we add texture to our sprite, but we can also make a sprite without using textures. A texture property is an optional property in the SKSpriteNode class. If texture is nil, that means we have no texture to stretch, so the contract parameter is ignored. Let's open our GameScene.swift file and make a variable of SKSpriteNode, just below the backgroundNode declaration:

var spriteWithoutTexture : SKSpriteNode?

Now, with the preceding declaration, we have declared spriteWithoutTexture as optional. Since we have declared it optional, texture need not require a value. Now under didMoveToView, add following function:

 func addSpriteWithoutTexture(){ spriteWithoutTexture = SKSpriteNode(texture: nil, ...

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