一些代码:
Menu.Handle_MouseOvers(MousePosition); //Runs function below
void Handle_MouseOvers(Vector2<int> &MousePositions) ///Runs function below
{
if (MenuButtons.size() > 0)
MenuButtons[0].CheckContains(MousePositions);
}
void CheckContains(Vector2<int> &MousePositions)
{
if (ButtonShape.GetShape() == "Rect" && ButtonShape.GetRect().Contains(MousePositions)) ///This doesn't run sometimes
{
MouseOver = true;
std::cout << "MouseOver is true" << std::endl;
}
else{
std::cout << "mouseOver is false" << std::endl;
MouseOver = false;
}
}
出于某种原因,ButtonShape.GetRect().Contains(MousePositions) 只运行了大约 80% 的时间。我在函数中放置了一些 couts,当它失败时,它根本不运行该函数。我不知道为什么它大部分时间都可以工作,哈哈。有没有人有任何想法?任何帮助将不胜感激。
将此添加为编辑;
bool Contains(Vector2<int> &MousePosition)
{
std::cout << MousePosition.x << " " << MousePosition.y << std::endl;
if (MousePosition.x >= x && MousePosition.x <= x + Width && MousePosition.y >= y && MousePosition.y <= y + Height)
return true;
else
return false;
}