PDA

View Full Version : Sprite Animation Backwards ... possible?



robert83
02-08-2011, 04:43 PM
Hello Everyone,

My next problem is (cause I'm trying to not waste more memory then needed for images) is this , I have a rotating moon, that turns to you, then Yawns...and turns back... waits for a bit and does this again.

Currently I'm doing it like this :


Case round(Moon.AnimPos) of
0..71 : Moon.AnimSpeed:=20;
72..85 : Moon.AnimSpeed:=10;
86..155 : Moon.AnimSpeed:=20;
156 :
begin
Moon.AnimStart:=156;
Moon.AnimStop:=156;
Counter:=Counter+1;
if Counter = 400 then
begin
Moon.AnimStart:=0;
Moon.AnimStop:=156;
Moon.AnimPos:=0;
Counter:=0;
end;
end;
end;

The problem is that 86..155 should not be there... it's exactly the same as 0..71 but only in reverse... I could not figure out how can I move a Sprite Animation backwards ... tried the obvious...by setting sSprite.AnimStart:=71 , AnimStop:=0 but does not work...

1. Is this solvable?
2. I thought about it that maybe I'm completely wrong here... and the SpriteEngine is only supposed to go trough images in one direction and that is only forward and not backwards.


Thanks
Rob

User137
02-08-2011, 09:30 PM
I would do it with sine-wave, because it makes smooth moves.

Hope these bits help, its not ready code so you would have to adapt it:

const ToRad = 0.0174532925199433; // PI / 180 = Deg To Rad
...
Counter:=(Counter+1) mod 360;
Moon.AnimPos:=72+72*sin(Counter*ToRad);

WILL
02-08-2011, 11:32 PM
Hi Robert, welcome to PGD. :)

I'd like to ask you to please put your code into proper code blocks so it's easier to read in the forums. Thanks.