I have completed the swift Monster game tutorial, implementing entity component based framework.

Afterwards, I read about GKSKNodeComponent. It seems that this component class should be used instead of GKComponent for the SpriteComponent class. I was hoping this would solve the problem of correlating sprites in the game scene world and the list of the game GKEntities, but I failed to get it working.

My question is… when should the GKSKNodeComponent be used? Some example code would be rather useful at this present time!


GKSKNodeComponent was introduced in iOS 10 and the tutorial originally targeted iOS 9. To use the GKSKNodeComponent in this game set the deployment target to 10.0 in the General section of the project file.

I would then change the subclass of SpriteComponent to GKSKNodeComponent. Then add a size property to the class and set it in the init(texture:) initializer to the size of the texture.

let size: CGSize

init(texture: SKTexture) {
    size = texture.size()
    node = SKSpriteNode(texture: texture, color: .white, size: texture.size())

Also remove let node: SKSpriteNode since that property conflicts with the node property of GKSKNodeComponent.

The size property is added to resolved the errors that are raised since SKNode doesn’t have a size property. In the project you can remove node from spriteComponent.node.size so it uses the size property calculated from the texture upon initialization.

Let me know if you have anymore questions!

Thanks mr natural. I got it working but didn’t resolve the issue I was trying to find a work around for (off topic).

Off topic insight… I was trying to make my nodes touch enabled but couldn’t figure out how to associate node touches to the GKEntities… I’m hoping mr wenderlich will release a tutorial to solve all my woes…