As far as I understand, you cannot change the frequency of a Timer once you set it initially. So even though you have the frequency tied to the timeManager variable, it will only use the initial value of timeManager - which is 3000.
You would run into the same issue with GameSalad. Something like: Timer Every random(3,10) seconds would NOT trigger the Timer like this: 3,5,7,8,4,10,6,3,etc⦠Instead, it would choose the initial random number, say 4, and trigger the Timer like this: 4,4,4,4,4,4,4,etcā¦
The same thing is happening here. Both Corona and GameSalad are built upon Lua, so maybe that is simply a limitation of the language.
It seems that you cannot have a Timer that fires repeatedly with a variable frequency.
The workaround is to wrap the Timer in a function, and then call the function repeatedly.
This code will give you want you want:
-- declare variables
local myTimer
local timeManager = 3000
local ballSpeed = 6000
local t = display.newText( timeManager, 115, 105, "ArialRoundedMTBold", 21 )
local physics = require ("physics")
--\> start physics engine and set the gravity
physics.start()
physics.setScale( 60 )
physics.setGravity(0,0)
-- set text color
t:setTextColor( 255, 255, 255 )
local function spawnRandomBall()
local rndBall = display.newImage( "ball\_orange.png" ) -- grab the ball from pool sample
rndBall.x = 40 + math.random( 240 )
rndBall.y = 10
physics.addBody( rndBall, { bounce=0.1, radius=14 } )
rndBall.myName = "orange"
rndBall.isHit = false
transition.to(rndBall, {time=ballSpeed, y=360})
if timeManager \>= 1000 then
timeManager = timeManager - 100
ballSpeed = ballSpeed - 200
t.text = timeManager
end
-- call this function again
myTimer = timer.performWithDelay( timeManager, spawnRandomBall)
end
-- set everything in motion
spawnRandomBall()
Just paste that into your main.lua file and you should be good to go.
Hope this helps!
Joe [import]uid: 8444 topic_id: 4092 reply_id: 14564[/import]