Search code examples
iosiphoneswiftuiviewsklabelnode

Unable to draw SKLabelNode in front of UIView


I'm adding a SKLabelNode in my GameScene.swift by using the following code

 let scoreLabel = SKLabelNode(fontNamed: "GillSans-BoldItalic")
    scoreLabel.fontSize = 25
    scoreLabel.text = "Text"
    scoreLabel.position = position
    scoreLabel.zPosition = 3000
    self.addChild(scoreLabel)

However, when the label appears it is behind a UIView (that contains a couple of UIImageView elements), despite it's intentionally high .zPosition.

How can I make it appear in front of my UIView? I can't find a .zPosition equivalent on UIView.


Solution

  • The zPosition only relates to other nodes within the same scene. If you have a UIView that has been added on top of your SKView that holds the scene, subviews of this view will always appear on top of nodes in your scene. Consider adding your images as nodes inside your SKView instead of in their own view.