TimKrs
TimKrs

Reputation: 67

How can I create an node using Inheritance and the Sprite Kit?

I try to create multiple nodes when loading a level. For this I use the following code in GameScene.swift:

func createUnits() {

    let myUnit = Unit()
    myUnit.attack()
}

The Unit class is still kept very simple:

class Unit: GameScene {

    var livePoints = 10
    var damage = 5
    var movement = 1

    func attack() {
        print("Attack!!")
    }
}

When compiling, I get the following error at let myUnit = Unit():

Thread 1: EXC_BAD_ACCESS (code=2, address=0x7ffee771cff8)

Does anyone have an idea, how to create a node without get this error?

Thank you in advance.

Upvotes: 0

Views: 28

Answers (1)

FullMetalFist
FullMetalFist

Reputation: 208

looks like its not a Node, but a Scene. the first line in your Unit class shows you are subclassing GameScene instead of a SKNode

Upvotes: 1

Related Questions