'How can i make my sprite move after mouse
i am trying to make my first game, but i am a completely newbie at SFML, and i wanted to make my sprite always move to mouse x position(without clicking any button) but i don't know how, i've tried many things and none of it worked + on internet, there are only tutorials how to make a "drag a sprite" code and for sfml 1.6 from 2013(i am using SFML 2.x).
Solution 1:[1]
You should just update the sprite position to the mouse position every frame.
while (window.isOpen()) // Your update loop
{
[...]
sprite.setposition(sf::Mouse::getPosition);
[...]
window.draw(sprite);
}
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 | Psolyvem |
