当我在模拟器或手机中构建应用程序时,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
}
}))
}
}
}
期望它可以根据加载的图像创建运动背景。