Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Interest on retro and future game projects
#8
Solved,

You restart the animation each frame the character is moving, that's why you don't see animation at all. Instead you must only enable/disable the animation on state transition -when the character starts or stops walking. Here I use a bool variable called walking used to track state changes, and update accordingly:

Code:
bool walking = false;
while (TLN_ProcessWindow()) {
    float fx = 0;
    float fy = 0;

    if (TLN_GetInput(INPUT_RIGHT))
        fx = 1.0f;
    if (TLN_GetInput(INPUT_LEFT))
        fx = -1.0f;
    if (TLN_GetInput(INPUT_DOWN))
        fy = 1.0f;
    if (TLN_GetInput(INPUT_UP))
        fy = -1.0f;

    if (!walking && (fx != 0 || fy != 0))  {
        TLN_SetSpriteAnimation(0, 0, beeb_walk, 0);
        walking = true;
    }
    else if (walking && (fx == 0 && fy == 0))  {
        TLN_DisableAnimation(0);
        TLN_SetSpritePicture(0, 0);
        walking = false;
    }

    layer_x += fx;
    layer_y += fy;
    TLN_SetLayerPosition(0, layer_x, layer_y);
    TLN_DrawFrame(frame++);
}
Reply


Messages In This Thread
RE: Interest on retro and future game projects - by megamarc - 04-05-2020, 04:44 AM

Forum Jump:


Users browsing this thread: 2 Guest(s)