Classy clash texture

in the classy clash project inside the C++ Fundamentals: Game Programming For Beginners, when i added a variable to flip the texture , the texture disappear when i flip it, i copied the code and tried various versions and i got nothing.

Here is the map without the texture ( i pressed the left button so flip variable is -1)

here is the texture working fine (flip variable is 1)

Hello Hamza,

Can you show us your code for flipping the texture and then drawing your character? That’ll help identify what the problem could be.

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.

Based on what you’ve shown me, I find it a little odd that it didn’t work. That said, I’m glad you were able to find a solution!

i just left and came back tomorrow and it worked i really don’t know how it got fixed

This topic was automatically closed 20 days after the last reply. New replies are no longer allowed.

Privacy & Terms