Hello, I've recently been learning about programming in C++ with SDL and have learned a great deal with the help of the tutorials on
http://lazyfoo.net. Currently I'm messing around with clipping sprite sheets and cycling through the frames to try and imitate how they move in the game that they come from. Taking the directional sprites from Mystical Ninja for the SNES I've been able to cycle through the left and right movement sprites in a way that copies the game exactly. The problem comes when using the up and down sprites, they end up cycling so quickly that it looks odd. The left and right movements have 8 sprites that they cycle through while the up and down only have 4 so they complete much faster. Other than including more sprites to even out the speed is there another way to slow the rate at which they cycle to give off a more natural feel?
Here's the code that determines which frame is chosen to be drawn to the screen
//xVel and yVel are there to measure velocity
//the reason for the if(frame >=4) is so that the standing clip which //is frame 0 doesn't get cycled through while running is animating
//frame is put into an SDL_Rect that determines picture clippage
//apply_surface is a modified BlitSurface fuction that takes parameters
//(x coordinate, y coordinate, picture, main window,SDL_Rect)
void Dot::show()
{
if (xVel < 0)
{
status = GoemonLeft;
frame++;
if(frame >= 8)
{
frame = 1;
}
}
else if(xVel > 0)
{
status = GoemonRight;
frame++;
if(frame >= 8)
{
frame = 1;
}
}
else if(yVel < 0)
{
status = GoemonUp;
frame++;
if(frame >= 4)
{
frame = 1;
}
}
else if(yVel > 0)
{
status = GoemonDown;
frame++;
if(frame >= 4)
{
frame = 1;
}
}
else
{
frame = 0;
}
if (status == GoemonRight)
{
apply_surface( x, y, dot, screen, &ClipsRight[ frame ] );
}
else if(status == GoemonLeft)
{
apply_surface( x, y, dot, screen, &ClipsLeft[ frame ] );
}
else if(status == GoemonUp)
{
apply_surface(x, y, dot, screen, &ClipsUp[frame]);
}
else if(status == GoemonDown)
{
apply_surface(x, y, dot, screen, &ClipsDown[frame]);
}
}
Sorry if this doesn't classify as a beginner question and that my post was so long, making sure I include as many details as possible. Appreciate any help you can offer.