PDA

View Full Version : DXInput and DXSpriteEngine having some trouble.



Chesso
28-01-2005, 10:30 AM
Well im using DXTimer with an interval of around 30 to fresh the screen and check the keyboard state to see if i need to move my sprite or not. I tryed two timer's but then nothing would draw :(

My hero animation is 16 images 4 across and 4 down making up 128 by 128. So their 32x32 each and are all setup. For my hero sprite i have:

AnimeCount as 4.
AnimLooped as False //to begin with.
AnimSpeed as either 30/50 or 15 //tryed quite a few things.
AnimStart as 0 //facing downward.

err well now to the actuall problem...... When my map loads up and the hero on it i press say right key his animation plays while it is held.... veryyyyy slowlyyyy no matter what AnimSpeed or Update Interval is i cant get animation cycling quick enough.

And holding right key only works once and after that hitting that key and others (up,left,down) he does move as he should but his animation does not play. When DXInput is updated and a certain key is pressed i call my DoMove procedure with an argument specifying what key it was and this is what i do in it:


Procedure TFrmMain.HMove(Const Direction: ShortString);
Begin
Chesso.AnimLooped := True;
If (Direction = 'Right') Then Begin
Chesso.AnimStart := HRight;
Chesso.X := Chesso.X + 1;
End
Else If (Direction = 'Left') Then Begin
Chesso.AnimStart := HLeft;
Chesso.X := Chesso.X - 1;
End
Else If (Direction = 'Down') Then Begin
Chesso.AnimStart := HDown;
Chesso.Y := Chesso.Y + 1;
End
Else If (Direction = 'Up') Then Begin
Chesso.AnimStart := HUp;
Chesso.Y := Chesso.Y - 1;
End;
End;


Chesso is the sprite, HRight and HLeft etc are constants for the directions which i use when changing sprites AnimStart value.

cairnswm
28-01-2005, 11:38 AM
My guess is that the procedure is being called more than once - probably every time the frame updates. In the procedure you keep resetting the AnimationStart to the first frame of the animation so even if the animation frame tries to change it gets schanged back to the first one right away.

Chesso
28-01-2005, 12:19 PM
Well i tryed checking if it was already at that point but i guess that may not work either. Does anyone know a better way?