This should spawn 1 balloon every half second for 20 seconds, then 2 balloons every half second, etc.
You can stop the timers with stopSpawnIncrease()
and stopSpawn()
as needed.
local spawnIncreaseTimer
local spawnNumber=0
local function spawnIncrease()
spawnNumber=spawnNumber+1
spawnIncreaseTimer = timer.performWithDelay( 20000, spawnIncrease)
end
function stopSpawnIncrease()
timer.cancel( spawnIncreaseTimer )
end
local spawnTimer
function spwanBalloons()
for i=1,spawnNumber do
local allBalloons = {"green_balloon2.png", "red_balloon.png"}
ballons = display.newImage(allBalloons[math.random(#allBalloons)])
ballons.x = math.random(display.contentWidth)
ballons.y = display.contentHeight + 60
transition.to( ballons, { time=math.random(3500-speedBump, 4500-speedBump), y=-100} )
speedBump = speedBump + 15
end
spawnTimer = timer.performWithDelay( 500, spwanBalloons )
end
function stopSpawnTimer()
timer.cancel( spawnTimer )
end
function startGame()
scoreText = display.newText( "Score: 0", 0, 0, "Helvetica", 22 )
scoreText.x = centerX
scoreText.y = display.screenOriginY + 10
spawnIncrease() -- first call brings from 0 to 1 and starts timer
spwanBalloons()
end