Scrolling backgrounds - random and grouped!

here’s what i want to do - just not sure what the best approach would be programmatically speaking.

  • make several groups of images - these are to be used as scrolling seamless backgrounds
  • each group to have start and end designated backgrounds
  • each group to have 1 or more middle backgounds that can be called in sequence or randomly
  • at a given trigger, a seamless jump is made from current group to next group.
  • end BG is called next and then start BG of next group - loop

so perhaps an array of images

var level1BG = [bg1_start, bg1_1, bg1_2, bg1_3, bg1_end]
var level2BG = [bg2_start, bg2_1, bg2_2, bg2_3, bg2_4, bg2_5, bg2_end]

and then switch on level (groups)

var level = 1
switch level {
case 1 :  // use level1BG array for scrolls
case 2:  // use level2BG array ...

this works as a infinitely scrolling background- called from update - but doesn’t allow changing sprites on the fly.

    func backgroudScrollUpdate(){
        bg1.position = CGPoint(x: bg1.position.x - scrollPerFrameAmount, y: bg1.position.y)
        bg2.position = CGPoint(x: bg2.position.x - scrollPerFrameAmount, y: bg2.position.y)
        if (bg1.position.x < -(bg1.size.width / 2)) {
                bg1.position = CGPointMake(bg2.position.x + bg1.size.width, bg1.position.y)
        if (bg2.position.x < -(bg2.size.width / 2)) {
                bg2.position = CGPointMake(bg1.position.x + bg2.size.width, bg2.position.y)

could anyone point me in the right direction as to best way to approach this ?

many thanks !

edit: sorry, meant to say, I only work in Swift !

Do you mean you want to change elements in the arrays (images) as they are being used in the game?

Why not?
Where does bg1 and bg2 come from? Or did you mean bg1_1 and bg1_2?