I'm trying to create many sprites which are overlapping and hiding each other.
class BubbleNode: SKSpriteNode {
init() {
let texture = SKTexture(imageNamed: "body")
super.init(texture: texture, color: .clear, size: texture.size())
let eye = SKSpriteNode(imageNamed: "eye")
eye.zPosition = 1
eye.position = CGPoint(x: -20, y: 0)
let eye_right = eye.copy() as! SKSpriteNode
eye_right.position = CGPoint(x: 20, y: 0)
let mouth_smiling = SKSpriteNode(imageNamed: "mouth_smiling")
mouth_smiling.zPosition = 1
mouth_smiling.position = CGPoint(x: 0, y: -20)
addChild(eye)
addChild(eye_right)
addChild(mouth_smiling)
}
}
From my point of view, zPosition of child elements makes sense.
I'm adding bubbles like this:
func touchDown(atPoint pos : CGPoint) {
let n = BubbleNode()
n.position = pos
self.addChild(n)
}
So I expected sprites overlapping and hiding invisible parts.
Instead, I get bodies rendered first, then eyes and mouths rendered as siblings:
I tried to flip view.ignoresSiblingOrder
but it didn't help.