I copied this object spawning code from the documentation to play with the numbers and see how it works so i could apply it to the game i am currently working on.
this almost mimics what i am building currently but i need to increase either the velocity or spawn rate based on a timer or score, i cant seem to figure out how to do so.
local backGround = display.newImageRect("Images/BackGround1.png", display.contentWidth, display.contentHeight) backGround.x = display.contentCenterX backGround.y = display.contentCenterY local physics = require("physics") physics.start() physics.setGravity( 0, 0 ) -------------------------------------------------------------------------------- local spawnTimer local spawnedObjects = {} -- Seed the random number generator math.randomseed( os.time() ) local spawnParams = { xMin = 110, xMax = 250, yMin = -50, yMax = -50, spawnTime = 3000, spawnOnTimer = 12, spawnInitial = 0 } -- Spawn an item local function spawnItem( bounds ) -- Create an item local item = display.newCircle( 0, 0, 20 ) physics.addBody( item, "dynamic", {radius=20 , bounce = 0.5} ) item:setLinearVelocity( 0,100 ) -- Position item randomly within set bounds item.x = math.random( bounds.xMin, bounds.xMax ) item.y = math.random( bounds.yMin, bounds.yMax ) -- Add item to "spawnedObjects" table for tracking purposes spawnedObjects[#spawnedObjects+1] = item end local function spawnController( action, params ) -- Cancel timer on "start" or "stop", if it exists if ( spawnTimer and ( action == "start" or action == "stop" ) ) then timer.cancel( spawnTimer ) end -- Start spawning if ( action == "start" ) then -- Gather/set spawning bounds local spawnBounds = {} spawnBounds.xMin = spawnParams.xMin or 0 spawnBounds.xMax = spawnParams.xMax or display.contentWidth spawnBounds.yMin = spawnParams.yMin or 0 spawnBounds.yMax = spawnParams.yMax or display.contentHeight -- Gather/set other spawning params local spawnTime = spawnParams.spawnTime or 1000 local spawnOnTimer = spawnParams.spawnOnTimer or 50 local spawnInitial = spawnParams.spawnInitial or 0 -- If "spawnInitial" is greater than 0, spawn that many item(s) instantly if ( spawnInitial \> 0 ) then for n = 1,spawnInitial do spawnItem( spawnBounds ) end end -- Start repeating timer to spawn items if ( spawnOnTimer \> 0 ) then spawnTimer = timer.performWithDelay( spawnTime, function() spawnItem( spawnBounds ); end, spawnOnTimer ) end -- Pause spawning elseif ( action == "pause" ) then timer.pause( spawnTimer ) -- Resume spawning elseif ( action == "resume" ) then timer.resume( spawnTimer ) end end spawnController( "start", spawnParams )