Disclaimer: This is not the only or best way to achieve what you wanting. It is simply one possible solution
You need to implement a basic timer/counter to switch between the two appropriate images.
For this example I would store your sprite offsets in a 2D array int sprite_x[4][2];
- this would represent the four directions and the two image offsets for each. Then on a key press instead of using a bool array just have a single integer index int sprite_index;
for indexing the sprite offsets. All you would then need to do is have another integer value called something like int current_key;
which you would switch between 0 and 1.
// Used for indexing the 2D array
enum
{
WALK_LEFT,
WALK_RIGHT,
WALK_UP,
WALK_DOWN
WALK_MAX
};
// How many sprites per animation
const int NUM_KEYFRAMES = 2;
// 2D array to hold the x value offsets for sprites
int sprite_x[WALK_MAX][NUM_KEYFRAMES];
int sprite_index = WALK_LEFT; // Current animation
int current_key = 0; // Current keyframe for the animation
// Set up all the x value offsets in the array
sprite_x[WALK_LEFT][0] = 0;
sprite_x[WALK_LEFT][1] = 32;
sprite_x[WALK_RIGHT][0] = 64;
sprite_x[WALK_RIGHT][1] = 96;
.
.
.
You then simply update the sprite x value accordingly sprite.x = sprite_x[sprite_index][current_key];