I'm adding two SKSpriteNodes as children to another SKSpriteNode. The code looks like this:
let parentNode = SKSpriteNode(imageNamed: "ParentImage")
parentNode.position = CGPointMake(0,0)
parentNode.zPosition = 0
let child1 = SKSpriteNode(imageNamed: "ChildImage1")
child1.position = CGPointMake(0,0)
parentNode.addChild(child1)
child1.zPosition = -10
let child2 = SKSpriteNode(imageNamed: "ChildImage2")
child2.position = CGPointMake(0,0)
parentNode.addChild(child2)
child2.zPosition = 10
When I add the parentNode to my scene, the order of sprites in the z-plane, from back-to-front is
- parentNode
- child1
- child2
and sometimes, the expected
- child1
- parentNode
- child2
Does the zPosition property get over-ruled when a child is below the parentNode? Has anyone come across a bug like this or know of a fix?
In the GameViewController, skView.ignoresSiblingOrder = true
When I set it to false
, I get the first behaviour (parentNode, child1, child2) every time.