Endless scrolling (repeating) background in Spritekit game - Swift

后端 未结 6 1914
野的像风
野的像风 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:53

        func backgroudScrollUpdate(){
            BG .position = CGPoint(x: BG.position.x - 5, y: BG.position.y)
            BG2.position = CGPoint(x: BG2.position.x - 5, y: BG2.position.y)
            if BG2.position.x <= -self.frame.size.width {
                BG.position = CGPoint(x: self.frame.size.width, y: 0)
            }
            if BG.position.x <= -self.frame.size.width {
            BG2.position = CGPoint(x: self.frame.size.width, y: 0)
        }
    }
    

    -UPDATED FOR SWIFT 3.1-

    this is what I always use to make it work for the Y axis just switch all the extra stuff in the X positions to the Y positions

提交回复
热议问题