How to bring a SKSpriteNode to front?

前端 未结 4 1075
悲&欢浪女
悲&欢浪女 2021-01-03 18:26

How can I bring a SKSpriteNode to the front of all other node?

With UIView, I can use bringSubviewToFront to bring an uiview in front of other views.

4条回答
  •  天命终不由人
    2021-01-03 18:40

    This extension adds a bringToFront method to SKNode. This great for times when zPosition is inappropriate, and you want to rely on sibling ordering.

    extension SKNode {
        func bringToFront() {
            guard let parent = parent else { return }
            removeFromParent()
            parent.addChild(self)
        }
    }
    

    `

提交回复
热议问题