简体   繁体   中英

SpriteKit - SKShapeNode from a loaded SKScene not rendered

I'm loading a SKScene from a file. In it, a SKShapeNode that I can see on the screen. But if set the "custom class" to a class like TestNode below, the ShapeNode won't be rendered: implementing init with coder and debugging, I can see that the .scene is nil, even if in the "attributes editor" in Xcode, the parent is set to the Scene. I can even get userData I set on the Node. The node is initiated as isPaused = true, setting it to false doesn't help.

public class TestNode: SKNode {
    required init?(coder aDecoder: NSCoder) {
        super.init(coder: aDecoder)
    }
}

Any idea why the .scene property is nil?

Turned out that the custom class has to be of the exact same class as the node added in the scene editor.

So if you had a SKSpriteNode in the scene (.sks file) and set its custom class property, that custom class must also be a SKSpriteNode, it can't just be a SKNode.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM