【发布时间】:2015-05-07 08:29:56
【问题描述】:
我正在尝试垂直滚动游戏背景,它可以工作一段时间,后来背景变空。这是我尝试过的:
var background = SKSpriteNode(imageNamed: "bgPlayScene")
func addBG() {
let backgroundTexture = SKTexture(imageNamed: "bgPlayScene")
let shiftBackground = SKAction.moveToY(-backgroundTexture.size().height, duration: 9)
let replaceBackground = SKAction.moveToY(backgroundTexture.size().height, duration: 0)
let movingAndReplacingBackground = SKAction.repeatActionForever(SKAction.sequence([shiftBackground,replaceBackground]))
for var i = 0; i<3; i++ {
println(i)
//defining background; giving it height and moving width
background=SKSpriteNode(texture:backgroundTexture)
background.position = CGPoint(x: self.size.width/2, y: self.size.height/2)
background.size.width = self.frame.width
background.runAction(movingAndReplacingBackground)
self.addChild(background)
}
}
这就是我得到的:http://gyazo.com/3da3a267aeb030225fdb8c0d563276aa 我不知道我错过了什么。如果有其他更好的方法,请告诉我。
【问题讨论】:
-
你需要有两个滚动背景才能无限滚动:stackoverflow.com/a/20020023/437146
标签: swift sprite-kit skspritenode