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
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;
}
};
{
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;
}
};