So at the moment i have 32 x 32 tiles. I have a 32 x 32 sprite. I want the sprite to move from one tile to another in one go. That is one "right" click would move it into the other tile. This will make collision detection alot easier because the sprite will always be in 1 tile, and never halfway. However I want the transition animation between tiles to be "smooth". At the moment I am using the foo tutorial velocities to implement the animation,. see code below
if( event.type == SDL_KEYDOWN )
{
//Set the velocity
switch( event.key.keysym.sym )
{
case SDLK_RIGHT:velocity+=FOO_WIDTH/8;keypressed=1; status=FOO_RIGHT; break;
case SDLK_LEFT: velocity -= FOO_WIDTH/8 ;keypressed=1; status=FOO_LEFT;break;
case SDLK_UP: yvelocity-=FOO_HEIGHT/4; status=FOO_UP;break;
case SDLK_DOWN: yvelocity +=FOO_HEIGHT/4; status=FOO_DOWN; break;
}
}
//If a key was released
elseif( event.type == SDL_KEYUP )
{
//Set the velocity
switch( event.key.keysym.sym )
{
case SDLK_RIGHT:velocity-=FOO_WIDTH/4 ; break;
case SDLK_LEFT: velocity += FOO_WIDTH/4; break;
case SDLK_UP: yvelocity+=FOO_HEIGHT/4; break;
case SDLK_DOWN: yvelocity -=FOO_HEIGHT/4; break;
}
}
The problem is that because the velocity is adding/subtracting 32/4, it only moves 1/4 of a tile at a time. i want it to move a whole tile and look smooth. If i change the velocity to adding or subtracting 32, then it will look very choppy and also skip out on some animations =(. How can I implement this so it behaves like I want it to?