Data Realms Fan Forums
http://45.55.195.193/

Mastering control of animation frames!
http://45.55.195.193/viewtopic.php?f=73&t=31554
Page 1 of 1

Author:  Djinn [ Tue Aug 07, 2012 8:12 pm ]
Post subject:  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.

Author:  Coops [ Tue Aug 07, 2012 9:16 pm ]
Post subject:  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.

Author:  Djinn [ Wed Aug 08, 2012 12:39 am ]
Post subject:  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.

Author:  Coops [ Wed Aug 08, 2012 12:50 am ]
Post subject:  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.

Author:  Djinn [ Wed Aug 08, 2012 1:10 am ]
Post subject:  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.

Author:  Coops [ Wed Aug 08, 2012 1:18 am ]
Post subject:  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.

Author:  Djinn [ Wed Aug 08, 2012 2:59 am ]
Post subject:  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!

Page 1 of 1 All times are UTC [ DST ]
Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group
http://www.phpbb.com/