我正在玩swift,我想用SpriteKit做一个简单的游戏。应用程序的背景是应该重复的纹理图像。
我的意思是[img] [img] [img] [img]
我该怎么做?
在aditional我想永远地移动它。但我已经解决了这一部分。
这是我的代码:
func generateWave(){
var wave: SKSpriteNode = SKSpriteNode(imageNamed: "wave")
var moveWave = SKAction.moveByX(-wave.size.width * 2.0, y: 0, duration: NSTimeInterval(0.02 * wave.size.width * 2.0))
var resetWave = SKAction.moveByX(wave.size.width * 2.0, y: 0, duration: 0.0)
var moveWaveForever = SKAction.repeatActionForever(SKAction.sequence([moveWave,resetWave]))
wave.position = CGPoint(x:CGFloat(1),y:CGFloat(10))
wave.runAction(moveWaveForever)
self.addChild(wave)
}
答案 0 :(得分:2)
在后台移动后尝试使用for循环。像这样:
bgTexture = SKTexture(imageNamed: "wave")
var movebg = SKAction.moveByX(-bgTexture.size().width, y: 0, duration: 9)
var replacebg = SKAction.moveByX(bgTexture.size().width, y: 0, duration: 0)
moveForever = SKAction.repeatActionForever(SKAction.sequence([movebg, replacebg]))
for var i:CGFloat=0; i<3; i++ {
wave = SKSpriteNode(texture: bgTexture)
wave.position = CGPoint(x: bgTexture.size().width/2 + bgTexture.size().width * i, y: CGRectGetMidY(self.frame))
wave.size.height = self.frame.height
wave.runAction(moveForever)
self.addChild(wave)
} ##
我希望这有帮助!