我認爲這會幫助你,首先使用下面的代碼設置背景:
for index in 0..<2 {
let bg = SKSpriteNode(imageNamed: "Your image name")
bg.position = CGPoint(x: index * Int(bg.size.width), y: 0)
bg.anchorPoint = CGPoint(x: 0, y: 0)
bg.name = "background"
self.addChild(bg)
}
,然後使用此代碼移動背景:
self.enumerateChildNodes(withName: "background", using: {(node, stop) -> Void in
if let bg = node as? SKSpriteNode {
bg.position = CGPoint(x: bg.position.x - 3.0, y: bg.position.y)
if bg.position.x <= -bg.size.width {
bg.position = CGPoint(x: bg.position.x + bg.size.width * 2, y: bg.position.y)
}
}
})
@ the4kman我想,以及,雖然 – Pablo
沒有成功您可以考慮使用[粒子](https://stackoverflow.com/questions/39298383/background-animation-with-depth-in-spritekit)創建星星。 –
你是否使用瓷磚地圖進行了調查? – 0x141E