Ios 快速无限背景滚动

Ios 快速无限背景滚动,ios,xcode,swift,scroll,background,Ios,Xcode,Swift,Scroll,Background,我试图开发一个简单的游戏,与该游戏我需要一个无限的滚动背景。它工作了2次,在图像滚动了2次之后,它将图像添加到后期,而不是正确的位置 这是我的密码 移动背景功能 func moveBackground() { let backgroundVelocity : CGFloat = 10.0 self.enumerateChildNodesWithName("background", usingBlock: { (node, stop) -> Void in i

我试图开发一个简单的游戏,与该游戏我需要一个无限的滚动背景。它工作了2次,在图像滚动了2次之后,它将图像添加到后期,而不是正确的位置

这是我的密码

移动背景功能

func moveBackground() {
    let backgroundVelocity : CGFloat = 10.0
    self.enumerateChildNodesWithName("background", usingBlock: { (node, stop) -> Void in
        if let bg = node as? SKSpriteNode {
            bg.position = CGPoint(x: bg.position.x, y: bg.position.y  - backgroundVelocity)

            // Checks if bg node is completely scrolled off the screen, if yes, then puts it at the end of the other node.
            if bg.position.y <= -bg.size.height {
                bg.position = CGPointMake(bg.position.x , bg.position.y + bg.size.width * 2)
            }
        }
    })
}
func initializingScrollingBackground() {
    self.addChild(background)
    for var index = 0; index < 2; index++ {
        let bg = SKSpriteNode(imageNamed: "bg")
        bg.position = CGPoint(x: 0 , y: index * Int(bg.size.height))
        bg.anchorPoint = CGPointZero
        bg.name = "background"
        bg.zPosition = 10
        self.addChild(bg)

    }
}
func moveBackground(){
让背景速度:CGFloat=10.0
enumerateChildNodesWithName(“背景”,使用block:{(节点,停止)->Void in
如果让bg=节点为?SKSpriteNode{
bg.position=CGPoint(x:bg.position.x,y:bg.position.y-背景速度)
//检查bg节点是否完全从屏幕上滚动,如果是,则将其置于另一个节点的末尾。
如果此行中的bg.position.y:

bg.position = CGPointMake(bg.position.x , bg.position.y + bg.size.width * 2)
                                                          ^^^^^^^^^^^^^

你不应该使用高度而不是宽度吗?

干杯,伙计,这就成功了。不知道我怎么没注意到!