使用鼠标滚轮时如何更新光标?
How to update the cursor when I use mousewheel?
我的问题是,当我使用鼠标滚轮移动视图时,光标精灵
留在后面,它不会更新到光标本身,我该如何解决这个问题?
主游戏循环:
this->cursor->Update(window);
if (event->type == sf::Event::MouseWheelMoved)
{
if (event->mouseWheel.delta == 1)
{
this->view->move(sf::Vector2f(0, -25));
window->setView(*this->view);
event->mouseWheel.delta = 0;
}
else if (event->mouseWheel.delta == -1)
{
this->view->move(sf::Vector2f(0, 25));
window->setView(*this->view);
event->mouseWheel.delta = 0;
}
}
游标更新函数:
this->setPosition(static_cast<sf::Vector2f>(sf::Mouse::getPosition(*window)));
Github Link:
Capitalist Adventure - Project In Question
查看 SFML 论坛后,我找到了一个答案,说明为什么设置精灵位置功能没有将我的精灵光标设置到我的 mouse.The 原因是 sf::View 与屏幕坐标。
答案:
this->setPosition(window->mapPixelToCoords(sf::Mouse::getPosition(*window)));
我的问题是,当我使用鼠标滚轮移动视图时,光标精灵 留在后面,它不会更新到光标本身,我该如何解决这个问题?
主游戏循环:
this->cursor->Update(window);
if (event->type == sf::Event::MouseWheelMoved)
{
if (event->mouseWheel.delta == 1)
{
this->view->move(sf::Vector2f(0, -25));
window->setView(*this->view);
event->mouseWheel.delta = 0;
}
else if (event->mouseWheel.delta == -1)
{
this->view->move(sf::Vector2f(0, 25));
window->setView(*this->view);
event->mouseWheel.delta = 0;
}
}
游标更新函数:
this->setPosition(static_cast<sf::Vector2f>(sf::Mouse::getPosition(*window)));
Github Link: Capitalist Adventure - Project In Question
查看 SFML 论坛后,我找到了一个答案,说明为什么设置精灵位置功能没有将我的精灵光标设置到我的 mouse.The 原因是 sf::View 与屏幕坐标。
答案:
this->setPosition(window->mapPixelToCoords(sf::Mouse::getPosition(*window)));