Welcome, Guest. Please login or register. Did you miss your activation email?

Show Posts

This section allows you to view all posts made by this member. Note that you can only see posts made in areas you currently have access to.


Topics - Merlin_Foffi

Pages: [1]
1
Graphics / RectangleShape.getPosition always returns 0 for value
« on: February 03, 2024, 10:39:15 pm »
I wrote this struct to handle menus for a title screen, but anytime i call the hover function it never worked, and when i added the test prints to the console, it always printed 0 for the Box Pos X and Box Pos Y
and i don't know why. I thought about call by value mistakes but this is not even a passed object, it's for the struct itself. Also when i call .move() or reset the position inside of the hover function it still reports a 0,
but visibly changes the box when the windows get redrawn. Thanks in advance

struct Menu
{
    sf::Text displayName;
    MenuType type;
    sf::RectangleShape box;

    bool isHovered(sf::Vector2i mPos)
    {
        printf("Mouse Pos X: %d \n", mPos.x);
        printf("Mouse Pos Y: %d \n", mPos.y);
        printf("Box Pos X: %d \n", box.getPosition().x);
        printf("Box Pos Y: %d \n", box.getPosition().y);
        // check if mouse.x is in range of box
        bool xIn = mPos.x >= box.getPosition().x && mPos.x <= box.getPosition().x + box.getSize().x;
       
        // check if mouse.y is in range of box
        bool yIn = mPos.y >= box.getPosition().y && mPos.y <= box.getPosition().y + box.getSize().y;

        // only true if both are true
        return xIn && yIn;
    }
};
 

Pages: [1]
anything