I'm building a game with SpriteKit. This is my node tree: self.world.hydraAnchor.head
The problem is that head
can not be seen
The code is simple
let world = SKSpriteNode()
addChild(world)
...
let hydraAnchor = SKSpriteNode()
hydraAnchor.position = anchorsPosition
world.addChild(hydraAnchor)
let head = SKSpriteNode(imageNamed: "hydraHead")
head.position = CGPointMake(anchorsPosition.x, anchorsPosition.y + 50)
hydraAnchor.addChild(head)
I can not see head
when building the project, while println(hydraAnchor.children)
gives [<SKSpriteNode> name:'(null)' texture:[<SKTexture> 'hydraHead' (50 x 50)] position:{700.50396728515625, 2486.333251953125} size:{25, 25} rotation:0.00]
While when instead of adding head
to hydraAnchor
I do this:
world.addChild(head)
head
can be seen.
zPosition
, invisible
and alpha
properties are not related to the problem.
You are forgetting that the coordinate system of a node's child is different than that of the parent. Your parent node's "worldNode" position might be at x:500, y:500 and adding a child 20 points on top of the parent is going to x:0 y:20.
You are adding the child by using worldNode coordinates and not parent coordinates.