Hey ! just wanted to have a talk or just ask about what i did and if there was some simpler or more elegant way to do this. i added my own (different asset) character sprite with 18 frames by 3 layer
so 6 frames for layer, while idle animation sprite is 4 frame, running anim. is 6 frames
// MOVEMENT
Vector2 direction{};
if (IsKeyDown(KEY_A))
{
direction.x -= 1.0;
TileLayer = 16;
}
if (IsKeyDown(KEY_D))
{
direction.x += 1.0;
TileLayer = 16;
}
if (IsKeyDown(KEY_W))
{
direction.y -= 1.0;
TileLayer = 32;
}
if (IsKeyDown(KEY_S))
{
direction.y += 1.0;
TileLayer = 0;
}
if (Vector2Length(direction) != 0.0)
{
// set worldPos = worldPos + direction
worldPos = Vector2Add(worldPos, Vector2Scale(Vector2Normalize(direction), SPEED));
direction.x < 0.f ? rightLeft = -1.f : rightLeft = 1.f;
direction.y < 0.f ? upDown = -1.f : upDown = 1.f;
texture = run;
maxFrame = 6;
}
else
{
texture = idle;
}
i added variable for “TileLayer” which is variable that changes layer of the tile while 0 is layer 1, 16 layer 2 and 32 layer 3. and just added tilelayer modifer to each key press to cycle between layer while pressing just the right key for all directions + i added modifire for “maxFrame” to be 6 for running instead of 4 which is for idle animation.