| View previous topic :: View next topic |
| Author |
Message |
chriso
Joined: 21 Mar 2006 Posts: 6
|
Posted: Mon Apr 24, 2006 12:08 am Post subject: Time based movement |
|
|
I'm not used to a time based method, does anyone have any example code or tips?
Basically instead of moving a character by +1 or +2 (which just flies around the screen using the while loop), I want to control everything using a timer.
I couldn't seem to find anything specific searching the forums. |
|
| Back to top |
|
 |
KawaGeo
Joined: 27 Aug 2005 Posts: 191 Location: Calif Mountains
|
Posted: Mon Apr 24, 2006 1:30 am Post subject: |
|
|
Take a look at my code in LED Timer which comes with Lua Player distribution. This should give you some ideas how to use a timer.
Have fun! _________________ Geo Massar
Retired Engineer |
|
| Back to top |
|
 |
chriso
Joined: 21 Mar 2006 Posts: 6
|
Posted: Mon Apr 24, 2006 2:12 am Post subject: |
|
|
Which example? I've only got a clock face one.
I've had a stab at trying to work out the frames per second. How does this look?
| Code: |
col_white = Color.new(255,255,255)
timer = Timer.new()
timer:start()
counter = 0
fps = 0
while true do
-- current time since timer started (milliseconds)
now = timer:time()
-- increase the frame counter
counter = counter + 1
-- if we are at 1 second
if now > 1000 then
-- frames per seconds = counter ?
fps = counter
-- reset
timer:reset()
counter = 0
timer:start()
end
screen:clear()
screen:print(10,10,"time:"..now, col_white)
screen:print(10,20,"counter: "..counter, col_white)
screen:print(10,30,"fps: "..fps, col_white)
screen.waitVblankStart()
screen:flip()
end
|
|
|
| Back to top |
|
 |
imhotep
Joined: 13 Dec 2005 Posts: 41
|
|
| Back to top |
|
 |
|