首页 > 解决方案 > 构建应用程序时,SKSpritenode 未显示在模拟器或手机中

问题描述

当我在模拟器或手机中构建应用程序时,SKspritenode 未显示。

我正在关注如何在 swift/xcode 中创建移动背景的 youtube 指南。我构建时没有显示我的图像。我尝试了以下方法:




class GameScene: SKScene {

    var ground = SKSpriteNode()



    override func didMove(to view: SKView) {
        self.anchorPoint = CGPoint(x: 0.5, y: 0.5)

}

    override func update(_ currentTime: CFTimeInterval) {

}
    func createGrounds() {
        for i in 0...3 {

            let ground = SKSpriteNode(imageNamed: "green")
            ground.name = "Ground"
            ground.size = CGSize(width: (self.scene?.size.width)!, height: 250 )
            ground.anchorPoint = CGPoint(x: 0.5, y: 0.5)
            ground.position = CGPoint(x: CGFloat(i) * ground.size.width, y: -(self.frame.size.height / 2))

            self.addChild(ground)


        }

        func moveGround() {

            self.enumerateChildNodes(withName: "Ground", using: ({

            (node, error) in
                node.position.x -= 2

                if node.position.x < -((self.scene?.size.width)!) {

                    node.position.x += (self.scene?.size.width)! * 3

                }
}))
}
}
}

期望它根据加载的图像创建一个移动的背景。

标签: swiftxcode

解决方案


推荐阅读