forums.ps2dev.org Forum Index forums.ps2dev.org
Homebrew PS2, PSP & PS3 Development Discussions
 
 FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

Timer or Frame based. which is better?

 
Post new topic   Reply to topic    forums.ps2dev.org Forum Index -> PSP Lua Player Development
View previous topic :: View next topic  
Author Message
thsock



Joined: 25 Sep 2005
Posts: 25

PostPosted: Sun Nov 20, 2005 11:24 am    Post subject: Timer or Frame based. which is better? Reply with quote

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:

local timer = Timer.new()
stop = false
   if pfenemhealth <= 0 and pfenemorient == -1 then
      pfenemalive = false
      elapsedTenthSeconds = math.floor(timer:start() / 100 + 0.5)
      if elapsedTenthSeconds  <= 1 and pfenemalive == false then
         screen:blit(pfenemxpos, pfenemypos, pfflip.df1)
      elseif elapsedTenthSeconds  <= 2 and pfenemalive == false then
         screen:blit(pfenemxpos, pfenemypos, pfflip.df2)
      elseif elapsedTenthSeconds  <= 3 and pfenemalive == false then
         screen:blit(pfenemxpos, pfenemypos, pfflip.df3)
      elseif elapsedTenthSeconds  <= 4 and pfenemalive == false then
         screen:blit(pfenemxpos, pfenemypos, pfflip.df4)
      elseif elapsedTenthSeconds  <= 5 and pfenemalive == false then
         screen:blit(pfenemxpos, pfenemypos, pfflip.df5)
      elseif elapsedTenthSeconds  <= 6 and pfenemalive == false then
         screen:blit(pfenemxpos, pfenemypos, pfflip.df6)
      elseif elapsedTenthSeconds  <= 7 and pfenemalive == false then
         screen:blit(pfenemxpos, pfenemypos, pfflip.df7)
      elseif elapsedTenthSeconds  <= 8 and pfenemalive == false then
         screen:blit(pfenemxpos, pfenemypos, pfflip.df8)
      elseif elapsedTenthSeconds  <= 9 and pfenemalive == false then
         screen:blit(pfenemxpos, pfenemypos, pfflip.df9)
      elseif elapsedTenthSeconds  <= 10 and pfenemalive == false then
         screen:blit(pfenemxpos, pfenemypos, pfflip.df10)
      elseif elapsedTenthSeconds  <= 11 and pfenemalive == false then
         screen:blit(pfenemxpos, pfenemypos, pfflip.df12)
      elseif elapsedTenthSeconds  <= 12 and pfenemalive == false then
         screen:blit(pfenemxpos, pfenemypos, pfflip.df13)
      elseif elapsedTenthSeconds  <= 13 and pfenemalive == false then
         screen:blit(pfenemxpos, pfenemypos, pfflip.df14)
      elseif elapsedTenthSeconds  <= 14 and pfenemalive == false then
         screen:blit(pfenemxpos, pfenemypos, pfflip.df15)
      elseif elapsedTenthSeconds  <= 15 and pfenemalive == false then
         screen:blit(pfenemxpos, pfenemypos, pfflip.df16)
      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(480)
         timer:reset(0)
         timer:stop()
      end
Back to top
View user's profile Send private message
Durante



Joined: 02 Oct 2005
Posts: 65
Location: Austria

PostPosted: Sun Nov 20, 2005 2:42 pm    Post subject: Reply with quote

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

Anyway, frame based is better IMHO on a fixed hardware target like psp.
Back to top
View user's profile Send private message
KawaGeo



Joined: 27 Aug 2005
Posts: 191
Location: Calif Mountains

PostPosted: Sun Nov 20, 2005 3:04 pm    Post subject: Reply with quote

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:

if not pfenemalive then
   if elapsedTenthSeconds < 17 then
      screen:blit(pfenemxpos, pfenemypos, pfflip.df[elapsedTenthSeconds])
   elseif elapsedTenthSeconds  >= 30 then
      pfenemalive = true
      pfenemhealth = 20
      if charhealth < 100 then
         charhealth = charhealth + 10
      end
      score = score + 10
      pfenemxpos = math.random(480)
      timer:stop()
      timer:reset()
   end
end


Also, timer.reset() should come after timer.stop() for the sake of logic but not necessarily.
_________________
Geo Massar
Retired Engineer
Back to top
View user's profile Send private message Send e-mail
cheriff
Regular


Joined: 23 Jun 2004
Posts: 262
Location: Sydney.au

PostPosted: Sun Nov 20, 2005 7:00 pm    Post subject: Reply with quote

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!
Back to top
View user's profile Send private message
xigency



Joined: 11 Nov 2005
Posts: 1

PostPosted: Mon Nov 28, 2005 2:15 am    Post subject: Reply with quote

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.
Back to top
View user's profile Send private message
Display posts from previous:   
Post new topic   Reply to topic    forums.ps2dev.org Forum Index -> PSP Lua Player Development All times are GMT + 10 Hours
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2005 phpBB Group