滚动背景与3个图像

时间:2015-08-09 23:10:32

标签: xcode swift sprite-kit

我的让我们:

let background = SKSpriteNode(imageNamed: "background1")
let background2 = SKSpriteNode(imageNamed: "background2")
let background3 = SKSpriteNode(imageNamed: "background3")

这是我制作背景滚动的方式:

func makeBackground(){
        var backgroundTexture = SKTexture(imageNamed: "background1")
        var moveBackgroundByX = SKAction.moveByX(-backgroundTexture.size().width, y: 0, duration: 10)
        var replaceBackground = SKAction.moveByX(backgroundTexture.size().width, y: 0, duration: 0)
        var moveBackgroundForever = SKAction.repeatActionForever(SKAction.sequence([moveBackgroundByX, replaceBackground]))
        for var i:CGFloat = 0; i < 3; i++ {
            let background = SKSpriteNode(texture: backgroundTexture)
            background.position = CGPoint(x: backgroundTexture.size().width/2 + (backgroundTexture.size().width * i), y: CGRectGetMidY(self.frame))
            background.size.height = self.frame.height
            background.runAction(moveBackgroundForever)
            self.addChild(background)
        }
    }

像这样,它只循环background1,但我希望它按顺序滚动:“background1”,“background2”,“background3”,然后再次“background1”,就像那样。

0 个答案:

没有答案