Endless scrolling (repeating) background in Spritekit game - Swift

后端 未结 6 1845
野的像风
野的像风 2021-02-06 02:20

I want to Create a endless scrolling background for my spritekit game, iT should consist of one or two images probably, which repeat themselves? I found these one and two exampl

6条回答
  •  日久生厌
    2021-02-06 02:46

    You don´t need all that.

    Just use this function with the vars that you declared and the attributes that you used in didMoveToView.

    func backgroudScrollUpdate(){
        background1.position = CGPointMake(background1.position.x, background1.position.y - 1)
        background2.position = CGPointMake(background1.position.x, background2.position.y - 1)
        if background1.position.y == -UIScreen.mainScreen().bounds.height{
            background1.position = CGPointMake(0, 0)
            background2.position = CGPointMake(0, 0 + UIScreen.mainScreen().bounds.height)
        }
    }
    

    Then just call it in your update method.

    Of course, it is not the best way since it is readable for two images, when you have more go for a loop.

提交回复
热议问题