Timer or Frame based. which is better?

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

Moderators: Shine, Insert_witty_name

Post Reply
thsock
Posts: 25
Joined: Sun Sep 25, 2005 1:04 pm

Timer or Frame based. which is better?

Post by thsock »

Since I began my 2d shooter Insane, I have been using basic Timer based animations. example below
lumo tells me that frame based is betterand far easier.
Which should I use! and how do I use frame based?
I believe the animation plays at the same speed no matter what the frame rate while using timer based animations. Is that correct?

Code: Select all

local timer = Timer.new()
stop = false
	if pfenemhealth <= 0 and pfenemorient == -1 then
		pfenemalive = false
		elapsedTenthSeconds = math.floor&#40;timer&#58;start&#40;&#41; / 100 + 0.5&#41;
		if elapsedTenthSeconds  <= 1 and pfenemalive == false then
			screen&#58;blit&#40;pfenemxpos, pfenemypos, pfflip.df1&#41;
		elseif elapsedTenthSeconds  <= 2 and pfenemalive == false then
			screen&#58;blit&#40;pfenemxpos, pfenemypos, pfflip.df2&#41;
		elseif elapsedTenthSeconds  <= 3 and pfenemalive == false then
			screen&#58;blit&#40;pfenemxpos, pfenemypos, pfflip.df3&#41;
		elseif elapsedTenthSeconds  <= 4 and pfenemalive == false then
			screen&#58;blit&#40;pfenemxpos, pfenemypos, pfflip.df4&#41;
		elseif elapsedTenthSeconds  <= 5 and pfenemalive == false then
			screen&#58;blit&#40;pfenemxpos, pfenemypos, pfflip.df5&#41;
		elseif elapsedTenthSeconds  <= 6 and pfenemalive == false then
			screen&#58;blit&#40;pfenemxpos, pfenemypos, pfflip.df6&#41;
		elseif elapsedTenthSeconds  <= 7 and pfenemalive == false then
			screen&#58;blit&#40;pfenemxpos, pfenemypos, pfflip.df7&#41;
		elseif elapsedTenthSeconds  <= 8 and pfenemalive == false then
			screen&#58;blit&#40;pfenemxpos, pfenemypos, pfflip.df8&#41;
		elseif elapsedTenthSeconds  <= 9 and pfenemalive == false then
			screen&#58;blit&#40;pfenemxpos, pfenemypos, pfflip.df9&#41;
		elseif elapsedTenthSeconds  <= 10 and pfenemalive == false then
			screen&#58;blit&#40;pfenemxpos, pfenemypos, pfflip.df10&#41;
		elseif elapsedTenthSeconds  <= 11 and pfenemalive == false then
			screen&#58;blit&#40;pfenemxpos, pfenemypos, pfflip.df12&#41;
		elseif elapsedTenthSeconds  <= 12 and pfenemalive == false then
			screen&#58;blit&#40;pfenemxpos, pfenemypos, pfflip.df13&#41;
		elseif elapsedTenthSeconds  <= 13 and pfenemalive == false then
			screen&#58;blit&#40;pfenemxpos, pfenemypos, pfflip.df14&#41;
		elseif elapsedTenthSeconds  <= 14 and pfenemalive == false then
			screen&#58;blit&#40;pfenemxpos, pfenemypos, pfflip.df15&#41;
		elseif elapsedTenthSeconds  <= 15 and pfenemalive == false then
			screen&#58;blit&#40;pfenemxpos, pfenemypos, pfflip.df16&#41;
		elseif elapsedTenthSeconds  >= 30 and pfenemalive == false  then
			pfenemalive = true
			pfenemhealth = 20
			if charhealth < 100 then
				charhealth = charhealth + 10
			end
			score = score + 10
			pfenemxpos = math.random&#40;480&#41;
			timer&#58;reset&#40;0&#41;
			timer&#58;stop&#40;&#41;
		end
Durante
Posts: 65
Joined: Sun Oct 02, 2005 6:07 am
Location: Austria

Post by Durante »

Your code sucks. (sorry, I'm intoxicated.)

Anyway, frame based is better IMHO on a fixed hardware target like psp.
KawaGeo
Posts: 191
Joined: Sat Aug 27, 2005 6:52 am
Location: Calif Mountains

Post by KawaGeo »

IMHO, timer-based operation is more accurate than frame-rate-based since frame rate may varies during the gameplay.

The long series of elseif's could be greatly shortened by using an array. E.g.,

Code: Select all

if not pfenemalive then
   if elapsedTenthSeconds < 17 then
      screen&#58;blit&#40;pfenemxpos, pfenemypos, pfflip.df&#91;elapsedTenthSeconds&#93;&#41; 
   elseif elapsedTenthSeconds  >= 30 then
      pfenemalive = true
      pfenemhealth = 20
      if charhealth < 100 then
         charhealth = charhealth + 10
      end
      score = score + 10
      pfenemxpos = math.random&#40;480&#41;
      timer&#58;stop&#40;&#41;
      timer&#58;reset&#40;&#41;
   end
end
Also, timer.reset() should come after timer.stop() for the sake of logic but not necessarily.
Geo Massar
Retired Engineer
cheriff
Regular
Posts: 258
Joined: Wed Jun 23, 2004 5:35 pm
Location: Sydney.au

Post by cheriff »

KawaGeo wrote:IMHO, timer-based operation is more accurate than frame-rate-based since frame rate may varies during the gameplay.
Yes, but if you wait for the vblank before switching frames, you know for certain that 1/60seconds have passed since the last frame. You also save on not having to check the time and things like that. Of course this only applies if your app runs quick enough to get everything done at 60Hz. But I believe frame based is better in this context, but on PC where targets differ greatly in performance then you would most likely go with timers. (to keep in mind if you want to port it, or co-develop on pc)
Damn, I need a decent signature!
xigency
Posts: 1
Joined: Fri Nov 11, 2005 11:25 am

Post by xigency »

what i do is use frame based animations and use a timer and delay to keep it running at a good FPS. since theres somuch going on in my games, 60 fps is too fast so i go with around 20-30 fps.

but timer based animations looks like a good idea too. if some of my animations are designed for different target framerates, then i might try that.
Post Reply