O'Reilly logo

Swift Game Development - Third Edition by Stephen Haney, Siddharth Shekar

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 custom sprite

Next, let's add our custom sprite to the scene. We will use the same asset that we used to make the regular SpriteKit game. One difference is that this time we will use the bee as one of the enemies. So, add the bat-fly, bat, bee-fly, bee, madfly-fly, and madfly assets to the assets in the Enemies folder:

Adding custom sprite

Also, add the GameSprite.swift, Bee.swift, Bat.swift, and Madfly.swift files and make changes to them as explained in this section.

Here is the GameSprite.swift file:

import SpriteKit

protocol GameSprite {
    var textureAtlas: SKTextureAtlas { get set }
    var initialSize: CGSize { get set }
}

Here is the modified Bee.swift file:

import ...

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