Yh Mireben is right, i recommend you do something like this
//set a global to handle your character animation frame
int currentFrame;
if (dbUpKey() == true)
{
if (dbLeftKey() == true)
{
dbMoveObject ( 3, -4.0f);
dbTurnObjectLeft(3,5);
while (dbUpKey() == true)
{
dbSetObjectFrame(3, currentFrame);
if(currentFrame < 322)currentFrame++;
else currentFrame = 300;
}
}
else if (dbRightKey() == true)
{
dbMoveObject ( 3, -4.0f);
dbTurnObjectRight(3,5);
}
else dbMoveObject ( 3, -4.0f);
}
Havent tested it but it should be pretty straight forward.
If your looking for some code for many different situations, e.g. walking, running, jumping you should know that these animations will probably require different speeds which you will be forced to tweak.
So to avoid that i wrote a fairly simple function a while back in which you can replace your 3 lines there for 1 every time you use it.
Heres the function
movementAnimation(int startingAnim, int finalAnim, int Millisecs, int obj, bool reversed)
{
//if normal animation flow is required eg. iNCrement frames
if (reversed == false)
{
//animation based on the timer MOVEMENT ANIMATION
if(dbTimer() - animTimer >= Millisecs) //if >= millisecs have passed
{
if(CurrentAnimation < startingAnim || CurrentAnimation > finalAnim)
{
CurrentAnimation = startingAnim;
}
dbSetObjectFrame(obj, CurrentAnimation);
CurrentAnimation += 1;
animTimer = dbTimer(); //reset timer
}
}
//same as above except for reverse animation eg. walking backwards
else
{
//animation based on the timer MOVEMENT ANIMATION
if(dbTimer() - animTimer >= Millisecs) //if >= millisecs have passed
{
if(CurrentAnimation > startingAnim || CurrentAnimation < finalAnim)
{
CurrentAnimation = startingAnim;
}
dbSetObjectFrame(obj, CurrentAnimation);
CurrentAnimation -= 1;
animTimer = dbTimer(); //reset timer
}
}
}
just make sure you create a global "int animTimer"
This is how you would use it in your code.
if (dbUpKey() == true)
{
if (dbLeftKey() == true)
{
dbMoveObject ( 3, -4.0f);
dbTurnObjectLeft(3,5);
while (dbUpKey() == true)
{
//1st thing your sending in is the first animation of the sequence
//2nd final animation
//3rd speed at which you want that animation to go at(in milliseconds)
//4th object number in your case seems like 3
//5th is this a backwards animation or not
//if so then you woulld do this instead movementAnimation(322, 300, 40, 3, true);
//and the player would look like hes doing an animation backwards e.g. walking
movementAnimation(300, 322, 40, 3, false);
}
}
else if (dbRightKey() == true)
{
dbMoveObject ( 3, -4.0f);
dbTurnObjectRight(3,5);
}
else dbMoveObject ( 3, -4.0f);
}
Hope that helped