SpriteKit not respecting zPosition?

后端 未结 2 1963
情深已故
情深已故 2020-12-11 03:23

What effect addChild and zPosition really have on a scene?

I mean this: suppose I do this

sprite1.zPosition = 50;
sprite2.zPosition = 10;
sprite3.zPo         


        
相关标签:
2条回答
  • 2020-12-11 04:17

    If they have the same parent that would be true. In case they can different parents, the z order of parents is also taken into account.

    The standard behavior for scene rendering follows a simple pair of rules:

    1. A parent draws its content before rendering its children.
    2. Children are rendered in the order in which they appear in the child array.

    When you take z positions into account, here is how the node tree is rendered:

    1. Each node’s global z position is calculated.
    2. Nodes are drawn in order from smallest z value to largest z value.
    3. If two nodes share the same z value, ancestors are rendered first, and siblings are rendered in child order.

    You can find it well explained here under Understanding the Drawing Order for a Node Tree

    0 讨论(0)
  • 2020-12-11 04:23

    In your game view controller, set the ignoresSiblingOrder property to false (or NO in objective-C).

    let skView = self.view as SKView
    skView.ignoresSiblingOrder = false
    
    0 讨论(0)
提交回复
热议问题