Swift 如何使背景图像永远循环?

Swift 如何使背景图像永远循环?,swift,sprite-kit,Swift,Sprite Kit,我移动了背景图像,但没有重复。经过一次背景后,它会返回到灰色背景。如何让背景永远重复。这是我目前掌握的代码。这是图片:我在xcode中使用swift。多谢各位 override func didMoveToView(view: SKView) { // Background background = SKSpriteNode(imageNamed: "background") background.position = CGPointMake(self.size.

我移动了背景图像,但没有重复。经过一次背景后,它会返回到灰色背景。如何让背景永远重复。这是我目前掌握的代码。这是图片:我在xcode中使用swift。多谢各位

   override func didMoveToView(view: SKView) {

    // Background
    background = SKSpriteNode(imageNamed: "background")
    background.position = CGPointMake(self.size.width/2, self.size.height/2)
    self.addChild(background)

    // loop Background Image

    doAction1()

    }

     //loop background image 

     func loopBackground() {
     let moveToBottom = SKAction.moveByX(0, y: 5000 - self.frame.size.height -                
     background.size.height, duration: 100.0)

     let removeTheNode = SKAction.removeFromParent()
     let moveAndRemoveBackground = SKAction.sequence([moveToBottom, removeTheNode])
     background.runAction(moveAndRemoveBackground)

     }


    //background repeat action

    func doAction1() {
    let generateBackground = SKAction.sequence([
    SKAction.runBlock(self.loopBackground),
    SKAction.waitForDuration(1)])
    let endlessAction1 = SKAction.repeatActionForever(generateBackground)
    runAction(endlessAction1)

    }

就我个人而言,我认为这取决于你试图用背景做什么

在这种情况下,最好的办法是决定什么时候你需要换一个背景。基本上,如果用户正在平移屏幕(移动屏幕),那么一旦用户到达第一个屏幕的末尾,您就需要添加另一个背景。另外,如果它们只能向一个方向滚动,那么实际上只需要2个后台节点。将它们并排放置,一旦用户顺利通过第一个,将其移动到第二个的前面,反之亦然。如果他们可以在任何方向上移动屏幕,并且每个方向(左上、中上、右上、左中、中中、右中、左下、中下和右下)都有一个,则不会造成伤害,并通过使用户处于新中间位置的节点来重新定位所有屏幕

另一方面,我强烈建议实施一种称为视差的技术。我会解释,但我对它相当了解,也知道我不能公正地解释它,所以我想请你们读一读:这本书在解释视差方面做得非常好。这些例子使用的是Spritekit,但这种技术绝对可以转让

我希望这会有所帮助,我不擅长Swift,所以很抱歉,我不能为您提供示例代码