Time based movement

Discuss using and improving Lua and the Lua Player specific to the PSP.

Moderators: Shine, Insert_witty_name

Post Reply
chriso
Posts: 6
Joined: Tue Mar 21, 2006 12:10 am

Time based movement

Post by chriso »

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.
KawaGeo
Posts: 191
Joined: Sat Aug 27, 2005 6:52 am
Location: Calif Mountains

Post by KawaGeo »

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
chriso
Posts: 6
Joined: Tue Mar 21, 2006 12:10 am

Post by chriso »

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: 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
imhotep
Posts: 41
Joined: Tue Dec 13, 2005 9:15 pm

Post by imhotep »

Post Reply