smooth transition between tiles?

so yesterday i played around with the code for my game engine, and im quite happy with the result. i made the movement of the character tile based instead of pixel based, wich made collision and event triggering stuff very easy.

the only thing i cant seem to figure out is how to get the transitioning to be smooth.
the way im guessing i should do it is something like:

-player hits the down button.
-the actual character position is set to 1 tile below, and turned invisibel.
-a "fake" character that is pixel based appears in the previous position, and this fake character has a down animation.
-after the "fake" character stops, it wil be replaced by the real character, which is now 1 tile below.

during all this the player input will not affect player movement.
am i onto something, or am i just being stupid like always?
I don't see why you would need to do a distinction between a fake and a real character. Just take into account the current progress of walking to the next tile when calculating the on-screen position of the character.
what do you mean? for the walking between tile i have to have the character walk using pixels, thats y i thought i had to make a fake character cause my real character walks using tiles not pixels.
care to explain a bit more detailed how you suges i do it?
There are a few ways to do this.

The first way that comes to mind is to keep a separate physical position (in tiles) as well as a drawing position (in pixels). When you move, you update the physical position immediately, but update the drawing position gradually.

Here's some pseudocode to conceptualize:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
void Player::Update()  // called once per frame
{
  // assuming:
  //  tilesize is the pixels size of 1 tile
  //  move.x and move.y are the number of pixels per frame the player moves along
  //   the x and y axis (ie:  if moving left, move.x would be like -0.5 and move.y would be 0
  //   or something like that)
  //  'movestep' is a counter that starts at the number of frames it takes to move 1 tile
  //    (ie, tilesize / move), and counts down every frame.  Once it reaches 0, the movement
  //    is complete.  Will be 0 when the object is not moving

  if(movestep)
  {
    --movestep;
    playerdrawpos.x += move.x;
    playerdrawpos.y += move.y;

    if( movestep == 0 )  // done moving
    {
      // snap back to actual position to avoid rounding errors
      playerdrawpos.x = playerphysicalpos.x * tilesize;
      playerdrawpos.y = playerphysicalpos.y * tilesize;
    }
  }
}
i tried to impliment this into my code but my program seem to crash,
btw i dont use rect at all for my player position. my player right now is just a number inside of an array, and therefore i do not use player.x or player.y to configure my player position. instead i use playerx and playery, which are two normal integer type variables, im guessing i have not done anything correct in terms of the movement then?
nevermind i got it to work (the code i used is very ugly, but it works, lol)

but now my top layer seems to flicker every frame that i move :/
any ideas why?


oops, the flickering was caused by a misplace "SDL_Flip" function, works fine now :)
Last edited on
Topic archived. No new replies allowed.