making enter frames more reliable?

Hey guys,

I was wandering about referencing the system.time() to move an object as it runs the function (enterframe). What I mean is to make something move the same speed no matter the speed the program is running at and how many times it is calling enterframe.

At the moment my game makes platforms move up the screen by like; every frame a function is called to take 2 off y position. But I think if the ram is low and runs the game slower than my computer, the platforms will not keep up with time… If that makes sense…?

They also have to eventually be recycled to the top…

So basicly I need to know ‘How long was it since this function was ran’.
Code atm…

[lua]

local resetPlatforms = function()

    if platform.y <= 0 then

        platform.y = display.contentHight() + 50

    end

end

local movePlatforms = function()

    platform.y = platform.y - 2

end

local enterFrame = function()

    movePlatforms()

    resetPatforms()

end

Runtime:addEventListener(“enterframe”, enterFrame)

[/lua]

[lua]

local enterFrame = function( event )

 print( event.time )

end

[/lua]

Does that help?

Well, no (because I have no idea what it does or how to use it properly…)
Also, I have recently found the delta time forum and that was what I was trying to replicate :slight_smile:
http://www.coronalabs.com/blog/2013/06/18/guest-tutorial-delta-time-in-corona/#comment-39506
So that should be alright; although I am having some issues with it…

Thanks anyway!

Delta Time is exactly what you’re referring to - however if you not doing anyhting overly excessive then you won’t have too many concerns over just using enterFrame (on most devices). Remember not to worry about excessive optimisation at an early stage.

[lua]

local enterFrame = function( event )

 print( event.time )

end

[/lua]

Does that help?

Well, no (because I have no idea what it does or how to use it properly…)
Also, I have recently found the delta time forum and that was what I was trying to replicate :slight_smile:
http://www.coronalabs.com/blog/2013/06/18/guest-tutorial-delta-time-in-corona/#comment-39506
So that should be alright; although I am having some issues with it…

Thanks anyway!

Delta Time is exactly what you’re referring to - however if you not doing anyhting overly excessive then you won’t have too many concerns over just using enterFrame (on most devices). Remember not to worry about excessive optimisation at an early stage.