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.
Time based movement
Moderators: Shine, Insert_witty_name
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?
I've had a stab at trying to work out the frames per second. How does this look?
Code: Select all
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