Scrolling Game Development Kit Forum

SGDK Version 2 => Help, Errors, FAQ => Topic started by: Tanja on 2007-12-03, 01:31:12 PM

Title: animate sprite frames backwards?
Post by: Tanja on 2007-12-03, 01:31:12 PM
if i made one animation, and wanted it to be played normal but also in reversed direction, downcounting the frames, is that possible?
i tried this:
frame = 35
SpriteBase.SpriteAnimationType.ByFrame-1
but i didn't work. an if-condition was set, when i remove the -1 it works.
Title: Re: animate sprite frames backwards?
Post by: Tanja on 2007-12-03, 01:37:21 PM
hm, main problem seems to be the frame = 35 before beginning the animation... why?
Title: Re: animate sprite frames backwards?
Post by: durnurd on 2007-12-03, 01:40:02 PM
the Animation function takes a SpriteAnimationType and deals with it by itself.  The ByFrame type tells Animation function to increase frame by 1 every time it's called.  You can't subtract 1 from a SpriteAnimationType, that's like trying to find the answer to 10 + orange.  Instead, if you are indeed animating by frame, the simplest method of animation, that can generally be replaced with a different type of function:
Code: [Select]
Type: Do
Function: +
Input 1: frame
Input 2: 1
Output: frame
This is generally the same thing.  If you change the function to - it will animate backwards instead of forwards.  Or you could change the 1 to a -1 for the same effect without having to change the function.  I don't know if it will work correctly if frame is negative, though.  You'd have to do a bit of work to make sure it didn't go negative if it doesn't work when frame < 0.
Title: Re: animate sprite frames backwards?
Post by: Tanja on 2007-12-03, 01:57:04 PM
thank you very much, it works!  :D
and when the frame gets 0, a fatal error occurs. but that is fine, one can prevent that.