it works now, i deleted the code and started all over again, but here is the code :
a struct for the character settings :
struct CharacterSettings
{
Texture2D Texture;
float Scale;
float Flip;
Vector2 Position;
};
this is the INITIALIZATION
CharacterSettings OUH{
LoadTexture("characters/knight_run_spritesheet.png"),
4.0f,
1.0f,
{
(float)Win_Settings.x/2.0f - 4.0f * (0.5f * (float)OUH.Texture.width/6.0f),
(float)Win_Settings.y/2.0f - 4.0f * (0.5f * (float)OUH.Texture.height)
},
};
i created a function that takes the input and find a normalized and scaled vector that is the direction of movement, i check the flip variable and change it , create two rectangles to pass to the draw function where i put the flip variable
Vector2 FinalDirection= FindDirection(Map.Position,Win_Settings,Map.Scale,Speed);
if(Vector2Length(FinalDirection) != 0.0f){
Map.Position = Vector2Subtract(Map.Position,FinalDirection);
//FinalDirection.x < 0.0f ? rightleft = -1.0f : rightleft = 1.0f;
FinalDirection.x < 0.0f ? OUH.Flip = -1.0f : OUH.Flip = 1.0f;
}
// ------- drawing map image -------
DrawTextureEx(Map.Texture,Map.Position,Map.Rotation,Map.Scale,Map.Tint);
// ------- Drawing the character ----------
Rectangle Source{
0.0f,0.0f,
OUH.Flip * (Current_Knight.width/6.0f),
Current_Knight.height
};
Rectangle Dest{
knightPos.x, knightPos.y,
4.0f * Current_Knight.width/6.0f,
4.0f * Current_Knight.height
};
DrawTexturePro(Current_Knight,Source,Dest,Vector2{},0.0f,WHITE);
i used this code yesterday but it didnt work.