2
나는 Flappy Bird와 같은 게임을 만들고 내 배경 루프를 무한대로 만들어야합니다. 온라인에서 자습서를 찾았지만 그저 나를 위해 일하는 것이 아니며 그 이유를 알 수 없습니다.스위프트 3 - 배경 루프가 제대로 작동하지 않습니다.
이 지금까지
var Background = SKSpriteNode()
var txtBG = SKTexture(imageNamed: "Background")
var txtLand = SKTexture(imageNamed: "Ground")
var Ground = SKSpriteNode()
var moving:SKNode!
// Cena
override func didMove(to view: SKView) {
scene?.anchorPoint = CGPoint(x: 0, y: 0)
moving = SKNode()
self.addChild(moving)
//Ground
Ground = SKSpriteNode(texture: txtLand)
Ground.position = CGPoint(x:0, y: txtLand.size().height * 1.3)
Ground.setScale(2.5)
self.addChild(Ground)
//Background
Background = SKSpriteNode(texture: txtBG)
Background.setScale(2.0)
Background.position = CGPoint(x: self.size.width, y: txtLand.size().height * 5.2)
let BGmove = SKAction.moveBy(x: -txtBG.size().width * 2.0, y: txtLand.size().height * 5.2 , duration: TimeInterval(15))
let BGRepo = SKAction.moveBy(x: txtBG.size().width * 2.0, y: txtLand.size().height * 5.2, duration: 0.0)
let BGLoop = SKAction.repeatForever(SKAction.sequence([BGmove,BGRepo]))
for i in 0 ..< 2 + Int(self.frame.size.width/(txtBG.size().width * 2)) {
let i = CGFloat(i)
Background = SKSpriteNode(texture: txtBG)
Background.setScale(2.0)
Background.position = CGPoint(x:txtBG.size().width/2 + txtBG.size().width * i * 2.0, y: txtLand.size().height * 5.2)
Background.run(BGLoop)
self.addChild(Background)
}
어떻게됩니까 배경이 수평 이동뿐만 아니라 위쪽으로 이동하고 내가 왜 이해하지 못하는 시작 내 코드입니다.
도움이 될 것입니다.