int Game::MouseOnDot(float x, float y, RenderWindow &renderWindow) {
Rect<int> Dot;
Event event;
Dot.left = x;
Dot.top = y;
Dot.width = 20;
Dot.height = 20;
while (renderWindow.pollEvent(event)) {
float Mx = sf::Mouse::getPosition().x;
float My = sf::Mouse::getPosition().y;
if (event.type == Event::MouseButtonReleased&&Mx > x && Mx < Dot.height && My > y && My < Dot.width){
return 1;
}
else
return 0;
}
}
我不知道为什么如果在点上按下按钮它会返回 1 告诉其他函数关闭窗口,这将不起作用。我在鼠标位置上做错了吗?
while (renderWindow.isOpen()) {
processEvents(renderWindow);
float Time = clock.getElapsedTime().asSeconds();
float TimeDifference = Time - LastUpdateTime;
if (TimeDifference >= UpdateTime) {
processEvents(renderWindow);
y += 3;
if (y <= 770) {
if(Game::MouseOnDot(x, y, renderWindow)==1)
renderWindow.close();
Game::Spawn(renderWindow, Green_Dots, x, y);
LastUpdateTime = Time;
return;
当 MouseOnDot 重新输入 0 或 1 时,我仍然无法工作我在这里粘贴部分。它不会关闭窗口,我不知道为什么?