2015-07-13 103 views
0

我的問題是,當我用鼠標滾輪移動視圖時,光標精靈 停留在後面,它不會更新到光標本身,我該如何解決這個問題?當我使用鼠標滾輪時如何更新光標?

主遊戲循環:

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

+0

我的鼠標光標隱藏起來光標精靈看起來像光標,那不是它。 –

回答

1

看了SFML論壇之後,我發現了一個答案,爲什麼設置精靈位置函數沒有將我的精靈光標設置到我的鼠標上。原因是sf :: View使用座標on-屏幕。

答:

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