【问题标题】:Sprite Kit SKLabel not showing up over background pictureSprite Kit SKLabel 未显示在背景图片上
【发布时间】:2016-07-24 17:13:59
【问题描述】:

我正在尝试为我的游戏启动一个菜单屏幕,并创建了一个应该位于屏幕中间的 SKLabel。但问题是它没有出现。只有我的背景出现了。我不知道从哪里开始,我认为这可能与 z 位置有关,但我不确定。这是我的代码

import SpriteKit

class GameScene: SKScene {


override func didMoveToView(view: SKView) {


    let waterWorksBackgroundImage = SKSpriteNode(imageNamed: "WaterWorksBackground")
    waterWorksBackgroundImage.position = CGPoint(x: self.frame.size.width / 2, y: self.frame.size.width / 2 - 100)



    let startGameButton = SKLabelNode(fontNamed: "AvenirNext-Heavy ")
    startGameButton.name = "startGame"
    startGameButton.color = UIColor.blueColor()
    startGameButton.text = "Start Game"
    startGameButton.fontSize = 65
    startGameButton.position = CGPoint(x: self.frame.size.width / 2, y: self.frame.size.height / 2 + 100)



    //Adding to view
    self.addChild(startGameButton)
    self.addChild(waterWorksBackgroundImage)

}

此外,在我的控制台中,我收到一条错误消息,显示“2016-04-04 19:55:59.021 Waterworks2d[7829:1362855] CUIcatalog:无效请求:请求子类型而不指定成语”我不确定这是否有任何关系有了它,但谢谢!

【问题讨论】:

  • 错误在哪里,您是否尝试更改 z 位置?
  • 忽略该错误 - 每个人都会出现此错误,Apple 开发者论坛上有很多关于它的主题。
  • 您说您不确定是否支持 zPosition,但您还没有在代码中设置 zPosition - 有什么特别的原因吗?

标签: swift sprite-kit


【解决方案1】:

我认为问题在于您添加项目的顺序。由于您先添加背景,然后再添加背景。

反过来:

//Adding to view
self.addChild(waterWorksBackgroundImage)
self.addChild(startGameButton)

和或添加

startGameButton.zposition = 2

希望对您有所帮助。

【讨论】:

    猜你喜欢
    • 2014-06-17
    • 2015-09-27
    • 2013-11-29
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2020-03-08
    • 2013-10-28
    • 1970-01-01
    相关资源
    最近更新 更多