View unanswered posts | View active topics It is currently Wed Dec 25, 2024 5:33 pm



Reply to topic  [ 7 posts ] 
 Mastering control of animation frames! 
Author Message
User avatar

Joined: Sun Oct 29, 2006 4:26 am
Posts: 298
Reply with quote
Post Mastering control of animation frames!
Alright this is a quick one - how can I stop a framecount from increasing once it reaches a certain frame? I've tried (at work so I can't verify, but something like this)

Code:
if self.frame = 12
self.frame

But it doesn't seem to do anything that I can see. I've read elsewhere that lua can't modify SpriteAnimMode so I can't just set it to 0 or something. I suppose I could start with SpriteAnimMode at 0 and animate it entirely by lua, but it seems to me that there must be a simple way to just stop it once its reached a certain point.


Tue Aug 07, 2012 8:12 pm
Profile YIM
User avatar

Joined: Wed Feb 17, 2010 12:07 am
Posts: 1545
Location: That small peaceful place called Hell.
Reply with quote
Post Re: Mastering control of animation frames!
So you want your sprite to stop animating as soon as it gets to a certain frame?

Well first off, you don't need it to be animated through ini, unless you want looping. Just make sure the FrameCount is correct in the ini.

Code:
function Create(self)

   self.animTimer = Timer()
   
   self.frameChangeTime = 50 -- This is the time interval between changing frames (In miliseconds).
   
   self.maxFrame = 12 -- This is the frame at which you want the animation to stop at.

end

function Update(self)

   if self.Frame > self.maxFrame then
      self.Frame = self.maxFrame
   else
      if self.animTimer:IsPastSimMS(self.frameChangeTime) then
         self.Frame = self.Frame + 1
         self.animTimer:Reset()
      end
   end

end


And thats all there really is to it. Just have a timer help with changing Frames and to have a cap check to see if it goes over.


Tue Aug 07, 2012 9:16 pm
Profile
User avatar

Joined: Sun Oct 29, 2006 4:26 am
Posts: 298
Reply with quote
Post Re: Mastering control of animation frames!
Coops wrote:
So you want your sprite to stop animating as soon as it gets to a certain frame?

Well first off, you don't need it to be animated through ini, unless you want looping. Just make sure the FrameCount is correct in the ini.

Code:
function Create(self)

   self.animTimer = Timer()
   
   self.frameChangeTime = 50 -- This is the time interval between changing frames (In miliseconds).
   
   self.maxFrame = 12 -- This is the frame at which you want the animation to stop at.

end

function Update(self)

   if self.Frame > self.maxFrame then
      self.Frame = self.maxFrame
   else
      if self.animTimer:IsPastSimMS(self.frameChangeTime) then
         self.Frame = self.Frame + 1
         self.animTimer:Reset()
      end
   end

end


And thats all there really is to it. Just have a timer help with changing Frames and to have a cap check to see if it goes over.


It works, but when it gets to the last frame it flickers like crazy. I'll play with the variables to see if it makes a difference.


Wed Aug 08, 2012 12:39 am
Profile YIM
User avatar

Joined: Wed Feb 17, 2010 12:07 am
Posts: 1545
Location: That small peaceful place called Hell.
Reply with quote
Post Re: Mastering control of animation frames!
What do you mean it flickers? Do you still have the SpriteAnimMode in the ini?

If you do remove that. Otherwise it shouldn't be flickering.


Wed Aug 08, 2012 12:50 am
Profile
User avatar

Joined: Sun Oct 29, 2006 4:26 am
Posts: 298
Reply with quote
Post Re: Mastering control of animation frames!
Coops wrote:
What do you mean it flickers? Do you still have the SpriteAnimMode in the ini?

If you do remove that. Otherwise it shouldn't be flickering.


SpriteAnimMode and Duration are both removed - it still flickers between the last two frames of the animation.


Wed Aug 08, 2012 1:10 am
Profile YIM
User avatar

Joined: Wed Feb 17, 2010 12:07 am
Posts: 1545
Location: That small peaceful place called Hell.
Reply with quote
Post Re: Mastering control of animation frames!
Code:
function Create(self)

   self.animTimer = Timer()
   
   self.frameChangeTime = 50 -- This is the time interval between changing frames (In miliseconds).
   
   self.maxFrame = 12 -- This is the frame at which you want the animation to stop at.

end

function Update(self)

   if self.Frame >= self.maxFrame then
      self.Frame = self.maxFrame
   else
      if self.animTimer:IsPastSimMS(self.frameChangeTime) then
         self.Frame = self.Frame + 1
         self.animTimer:Reset()
      end
   end

end


Try this instead. This should fix it.


Wed Aug 08, 2012 1:18 am
Profile
User avatar

Joined: Sun Oct 29, 2006 4:26 am
Posts: 298
Reply with quote
Post Re: Mastering control of animation frames!
Coops wrote:
Code:
function Create(self)

   self.animTimer = Timer()
   
   self.frameChangeTime = 50 -- This is the time interval between changing frames (In miliseconds).
   
   self.maxFrame = 12 -- This is the frame at which you want the animation to stop at.

end

function Update(self)

   if self.Frame >= self.maxFrame then
      self.Frame = self.maxFrame
   else
      if self.animTimer:IsPastSimMS(self.frameChangeTime) then
         self.Frame = self.Frame + 1
         self.animTimer:Reset()
      end
   end

end


Try this instead. This should fix it.


Yeeep that worked. It's always something simple like that that prevents stuff from working properly!


Wed Aug 08, 2012 2:59 am
Profile YIM
Display posts from previous:  Sort by  
Reply to topic   [ 7 posts ] 

Who is online

Users browsing this forum: No registered users


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 post attachments in this forum

Search for:
Jump to:  
Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group.
Designed by STSoftware for PTF.
[ Time : 0.096s | 13 Queries | GZIP : Off ]