lua-users home
lua-l archive

[Date Prev][Date Next][Thread Prev][Thread Next] [Date Index] [Thread Index]


> and when I used loops it would freeze the screen instead of
> slowing down
>
> oh i'm building this in the corona sdk
>

I don't know that one, but let's try …

Basically your game engine should have a main loop something
like this:

    update(dt)
    draw(...)  -- sets up the new screen but does not show it yet
    eventhandler(...)  -- check keyboard, mouse, joystick etc
    render()  -- finally show the screen

"update" gets told how much time has elapsed since the last
time it was called.  It's in here that you can put code like:

   delay=delay+dt
   if delay > too_long then pass=false; delay=0
   else pass=true
   end

Then in "draw" you skip everything if "pass" is on.

In "eventhandler" you check for slowdown and set "too_long"
to something positive, or set "too_long" back to if the slowdown
is cancelled.