I tried to subclass SKSpriteNode in GameObject , and I would like to create objects outside the class of the game scene. Here is my GameObject code derived from SKSpriteNode :
import SpriteKit public class GameObject: SKSpriteNode { init( texture: SKTexture?, color: UIColor, size: CGSize, position:CGPoint, name:String ) { objectSize = size; objectName = name; objectSprite = texture;
To create a player instance from GameObject , I have to write:
let player = PlayerShip(100, 100, "PlayerShip") addChild(player)
However, addChild() does not work outside of gameScene . My goal is to create bullets from the PlayerShip class, but I cannot figure out how to do this. Does anyone have a suggestion?
source share