【问题标题】:SpriteKit: White Background As SKSceneSpriteKit:白色背景作为 SKScene
【发布时间】:2015-11-08 19:06:20
【问题描述】:

我有一个包含 SpriteKit 框架的 Swift 项目。当我在没有任何内容的情况下运行程序时,屏幕为黑色,节点计数器为 1。Main.storyboard 完全为白色,其中的类设置为SKView。节点计数器是否错误?它不应该是0,为什么背景是黑色而不是白色?

可能是一些必要的代码错误所在:

class GameViewController: UIViewController {

override func viewDidLoad() {
    super.viewDidLoad()

    let scene = GameScene() // class GameScene is a subclass of SKScene

    let skView = self.view as! SKView
    skView.showsFPS = true
    skView.showsNodeCount = true

    /* Sprite Kit applies additional optimizations to improve rendering performance */
    skView.ignoresSiblingOrder = false

    /* Set the scale mode to scale to fit the window */
    scene.scaleMode = .AspectFill
    scene.size = skView.bounds.size
    scene.anchorPoint = CGPointMake(0,0);
    skView.presentScene(scene)
}

【问题讨论】:

    标签: swift background sprite-kit storyboard skscene


    【解决方案1】:

    节点计数器是正确的。首先你用这行代码为skView对象设置节点计数器:

    skView.showsNodeCount = true
    

    然后你用这一行将对象添加到这个skView

    skView.presentScene(scene)
    

    此操作将节点计数器设置为1。您的场景是skView 上的单个节点

    关于黑屏:这是场景的默认背景颜色,您可以使用以下代码更改它,例如:

    scene.backgroundColor = UIColor.redColor()
    

    你的场景会是红色的

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2018-10-13
      • 2023-03-20
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2019-12-13
      • 2014-08-21
      • 1970-01-01
      相关资源
      最近更新 更多