【问题标题】:How to update the cursor when I use mousewheel?使用鼠标滚轮时如何更新光标?
【发布时间】:2015-07-13 02:59:08
【问题描述】:

我的问题是当我用鼠标滚轮移动视图时,光标精灵 停留在后面并且不会更新到光标本身,我该如何解决这个问题?

主游戏循环:

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 链接: Capitalist Adventure - Project In Question

【问题讨论】:

  • 我隐藏了鼠标光标,所以光标精灵看起来像光标所以不是它。

标签: c++ visual-studio visual-c++ sprite sfml


【解决方案1】:

查看 SFML 论坛后,我找到了为什么设置精灵位置函数没有将精灵光标设置到鼠标的答案。原因是 sf::View 与屏幕上的坐标混淆。

答案:

this->setPosition(window->mapPixelToCoords(sf::Mouse::getPosition(*window)));

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2012-09-29
    • 2011-08-28
    • 2014-11-23
    • 1970-01-01
    • 2017-09-03
    • 2018-05-13
    • 2010-12-08
    • 1970-01-01
    相关资源
    最近更新 更多