04-05-2020, 04:44 AM
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:
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++);
}