While computing the elapsed time since the previous “enterFrame” event is simple, having Corona compute this useful/very-often-needed value would be nice: It would remove a few lines of boiler-plate code the developer would have to write (possibly in more that one place) and/or the need for a global variable (or two). [import]uid: 1581 topic_id: 201 reply_id: 300201[/import]
What’s an example of where/how you would use this? I understand the idea; I’m just trying to see if there are other features implied here. [import]uid: 3007 topic_id: 201 reply_id: 424[/import]
In my current project I’m using it in two places ATM (NOTE: I’m making use of my code snippet from here):
... (code clip #1) ...
elseif kSTEP\_COMPUTE == 4 then
xStep = kMAX\_STEP \* math.sqrt(1 - (xSpeed-1)\*(xSpeed-1)) -- outCirc
yStep = kMAX\_STEP \* math.sqrt(1 - (ySpeed-1)\*(ySpeed-1)) -- outCirc
end
xStep = xStep \* event.lastFrameTime
yStep = yStep \* event.lastFrameTime
... (code clip #1) ...
In Code #1, I’m computing the x & y step size for a full second, then multiplying it by the elapsed time to get the step size for the current frame.
... (code clip #2) ...
local function onEnterFrame\_updateBoids( event )
for \_,b in ipairs(boidInfo) do
b.moveETime = b.moveETime + event.lastFrameTime
local pdone = b.moveETime / kBOID\_MOVE\_DUR
while true do
if pdone \< 1.0 then
... (code clip #2) ...
In Code #2, I’m using the elapsed time to keep track of the total time an object has been moving, then testing if it’s reached it’s destination or not.
As Corona based apps get more complex the likelihood of them averaging different frame rates on different devices will increase, and this is where something like ‘lastFrameTime’ will come in very handy.
[import]uid: 1581 topic_id: 201 reply_id: 444[/import]