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:
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 SpriteKit // Create the new class Bee, inheriting from SKSpriteNode // and adopting the GameSprite protocol: class Bee: SKSpriteNode, GameSprite { // We will store our size, texture atlas, and animations // as class wide properties. var initialSize: CGSize = CGSize(width: 28, height: 24) var textureAtlas:SKTextureAtlas...