SFML community forums

Help => General => Topic started by: Momentu on April 26, 2016, 06:23:45 pm

Title: how i can move sprite with mouse,help ASAP please
Post by: Momentu on April 26, 2016, 06:23:45 pm
i'am working on a chess project and i wanted to know how  i can move the pieces with mouse to a certain coordinate,i only started learning sfml 3 weeks ago i'am still a beginner
Title: Re: how i can move sprite with mouse,help ASAP please
Post by: eXpl0it3r on April 26, 2016, 07:11:59 pm
sf::Mouse::getPosition(window) provides you the position of the mouse.
sprite.setPosition() allows you to set the position of a sprite.
Title: Re: how i can move sprite with mouse,help ASAP please
Post by: Momentu on April 26, 2016, 07:17:05 pm
I know the coordinates of the chess pieces but how i can write that if i press with the  mouse on that coordinate
move this piece i tried to do it but failed.
Title: Re: how i can move sprite with mouse,help ASAP please
Post by: Tukimitzu on April 26, 2016, 11:04:59 pm
Use sf::Event to read when the mouse button is pressed. See detailed description (http://www.sfml-dev.org/documentation/2.3.2/classsf_1_1Event.php).

while window is open
  handle window events (if piece is selected and mouse was pressed, update position)
  other updates go here...
end while