雪碧套件中的垂直无限滚动背景

Vertical endless scrolling background in sprite kit

我正在制作游戏,我想让我的背景无限地垂直滚动,但我不知道如何开始。我对编码和 sprite 工具包还很陌生,所以非常感谢任何帮助。

有人知道我该怎么做吗?

我会给你一个概念上的答案,给你一个起点,因为你没有提供任何代码。

您需要多张屏幕大小的图像,并将它们垂直堆叠在一起。

然后您想将这些图像逐点向下移动。当其中一张图像的顶部到达屏幕底部时,将其放回图像堆栈的顶部。这将导致您的背景永无止境地滚动。

祝你好运!

您想要两个节点,一个开始,一个在其后。最后,永远循环。

 func createGroundForward() {
        let groundTexture = SKTexture(imageNamed: "Track")

        for i in 0 ... 1 {
            let ground = SKSpriteNode(texture: groundTexture)
            ground.zPosition = -4
            ground.position = CGPoint(x: 0, y: -groundTexture.size().height + (groundTexture.size().height   + (groundTexture.size().height * CGFloat(i))))

            addChild(ground)

            let moveLeft = SKAction.moveBy(x:0 , y: -groundTexture.size().height, duration: 5)
            let moveReset = SKAction.moveBy(x:0 , y: groundTexture.size().height, duration: 0)
            let moveLoop = SKAction.sequence([moveLeft, moveReset])
            let moveForever = SKAction.repeatForever(moveLoop)

            ground.run(moveForever)
        }
    }

然后将该函数添加到您的 didMove 函数(类似于 Sprite 的 viewDidLoad)。

 override func didMove(to view: SKView) {
        self.anchorPoint = CGPoint(x: 0.5, y: 0.5)

        createGroundForward()
    }