So, I’m trying to get the greenLight to spawn faster and faster based on the amount of time the game has been active. I thought I could just have the delay on the time a variable and once the time hit’s a certain point then the variables value would change and the timer would recognize this. Right now I have the variable to change base on the score. Could someone please show me how to do it with the score as well as another version where I use time versus the score to determine the speed of the spawning.
Much Obliged .
spawned = true – Spawn will equal true
greenLight = display.newImageRect( “greenLight.png”, 126, 126) ; – Render image to screen , One of the reasons this might be here is because when we remove the object from the screen we will want to genrate another one
greenLight.x = display.contentCenterX + columns[mRand(4)] — Randomly choos a column
greenLight.y = display.contentCenterY/ rows[mRand(4)] — Randomly choose a row
function greenLight:touch( e ) – Add 1 to the score each tome the user touches the greenLight
if(e.phase == “ended”) then
audio.play(pop_sound)
score = score + 1
end
scoreLabel.text = score
end
greenLight:addEventListener( “touch”, greenLight ) – Calling the funtion for the score
function spawnGreen()
if(spawned == true) then – Since Spawned is true we will :
print(spawned)
greenLight.name = greenLight — Give image a name
greenLight.x = display.contentCenterX + columns[mRand(4)] — Randomly choos a column
greenLight.y = display.contentCenterY/ rows[mRand(4)] — Randomly choose a row
greenLightY = math.round(greenLight.y) – This is it’s Y position rounded , don’t want to work with insanely high numbers
greenLightX = math.round(greenLight.x) – This is it’s X position rounded , don’t want to work with insanely high numbers
–[[ The code below could possibly be the answer to the overlaping spawning problem with MOh2
local greenLightCX , greenLightCY = greenLight:localToContent( 0, 0 )
greenLightYActualPosition = mRound(greenLightCX)
greenLightXActualPosition = mRound(greenLightCY)
–print( "The greenLights center position in screen coordinates: ", x, y )
x = 0
y = 0
prevX = greenLightXActualPosition
prevY = greenLightYActualPosition
]]
end
–if(5 == 5 ) then — This was used when I wanted spawn to equal false
– spawned = false
–end
–if(spawned == false ) then – When spawn equals false then the image will move around without drawing another image
– print( “…” )
— greenLight.x = display.contentCenterX + columns[mRand(4)]
– greenLight.y = display.contentCenterY/ rows[mRand(4)]
–print( "The coordinates are : " … mRound(greenLight.x) … " " … mRound(greenLight.y) )
–end
print( score )
end
delay = 1000
if score == 5 then
delay = 8000
end
spawner = timer.performWithDelay( delay, spawnGreen, -1 ) – 1 second, function, iterations