Welcome, Guest. Please login or register. Did you miss your activation email?

Author Topic: how i can move sprite with mouse,help ASAP please  (Read 2573 times)

0 Members and 1 Guest are viewing this topic.

Momentu

  • Newbie
  • *
  • Posts: 2
    • View Profile
    • Email
how i can move sprite with mouse,help ASAP please
« 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

eXpl0it3r

  • SFML Team
  • Hero Member
  • *****
  • Posts: 11032
    • View Profile
    • development blog
    • Email
Re: how i can move sprite with mouse,help ASAP please
« Reply #1 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.
Official FAQ: https://www.sfml-dev.org/faq.php
Official Discord Server: https://discord.gg/nr4X7Fh
——————————————————————
Dev Blog: https://duerrenberger.dev/blog/

Momentu

  • Newbie
  • *
  • Posts: 2
    • View Profile
    • Email
Re: how i can move sprite with mouse,help ASAP please
« Reply #2 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.

Tukimitzu

  • Full Member
  • ***
  • Posts: 117
  • Anti-Hero Member
    • View Profile
Re: how i can move sprite with mouse,help ASAP please
« Reply #3 on: April 26, 2016, 11:04:59 pm »
Use sf::Event to read when the mouse button is pressed. See detailed description.

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