Random Background and Changing base on score

what the easiest way to make the game start with a random back ground image and how would i change background base on the score for example when a 100 points is reached

score = 0 

local scoreTxt = display.newText(‘0’, 290, 10, native.systemFont, 15)

local function onGlobalCollision (event)

audio.play(bounceSnd)

score = score + 5                                               – just a timer so you can keep track… 

     scoreTxt.text = string.format("%d", score ) 

end

Runtime:addEventListener( “collision”, onGlobalCollision )

You could create a table with references to the images:

local backgrounds = { "resource/images/background1.png", "resource/images/background2.png", "resource/images/background3.png", "resource/images/background4.png", "resource/images/background5.png", }

The create a function to randomly pick a background:

local background = nil local function changeBackground() --Choose a random image local randomImageIndex = math.random(1, #backgrounds) --Remove existing background if background then background:removeSelf() end --Create new background background = display.newImage(backgrounds[randomImageIndex], 0, 0) --Send it to the back background:toBack() end changeBackground()

Something along these lines should work.

You could create a table with references to the images:

local backgrounds = { "resource/images/background1.png", "resource/images/background2.png", "resource/images/background3.png", "resource/images/background4.png", "resource/images/background5.png", }

The create a function to randomly pick a background:

local background = nil local function changeBackground() --Choose a random image local randomImageIndex = math.random(1, #backgrounds) --Remove existing background if background then background:removeSelf() end --Create new background background = display.newImage(backgrounds[randomImageIndex], 0, 0) --Send it to the back background:toBack() end changeBackground()

Something along these lines should work.