I'm trying to create a program that will endlessly loop a background (without scrolling). Currently, I have the background in a constant loop, but the position in which it recycles leaves a gap of blank space. How do I change the position of where the background recycles?

func createCloud () {
    for i in 0...3 {
        let background = SKSpriteNode(imageNamed: "test")
        background.name = "Test"
        background.size = CGSize(width: frame.size.width, height: 
        frame.size.height * 2)
        background.zPosition = 0
    //  background.position = CGPoint(x:  -(self.frame.size.width), y: CGFloat(i) * background.size.height)

func moveCloud () {
    self.enumerateChildNodes(withName: "Test", using: ({ (node, error) in
        node.position.y -= 2

        if node.position.y < -((self.scene?.size.width)!) {
            node.position.y += ( self.scene?.size.width)! * 3


I expect to see the beginning of the background positioned at the end of the background after 1 full loop.

Loop example: enter image description here

  • "the position in which it recycles leaves a gap of blank space", can you elaborate that statement please? – holex Apr 11 at 14:58
  • Um... as of right now your code would not work the way you want it to. You have all your bg nodes in the same position, so on you theoretically will only see one of them, when one hits -width (you want -height) all will go to 2* width (again you want height) , leaving a little hooch of blackness because you moved all, not one, and you moved it to a spot that is only partially off screen – Knight0fDragon Apr 12 at 1:43

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.