Jump to content
  • Advertisement
Sign in to follow this  
chosenkill6

SDL mouse dragging

This topic is 2535 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

I am trying to add mouse dragging in my game of Pong, but i have no clue how to do this... Would really appreciate some help
I have tried so much but dragging just doesn't seem to work. What i would like to do is, allow the user to use their mouse to drag the paddle in pong. I know that this would be really hard gameplay wise etc but i am doing it in pong because i already have the game made and i want to learn mouse events so i decided to do it in Pong :P

Share this post


Link to post
Share on other sites
Advertisement
One way to do it is to handle the mouse button down, mouse button up, and mouse move events. In the mouse button down event, set a flag (most likely a bool, set to true) that you can check in the mouse move event, to see if the button is down. In the mouse button up event, set the flag to false. Then, in the mouse move event, you check the flag and, if the flag says the button is pressed, move the paddle with the mouse.

That is not unique to SDL. SDL might have a specific way to check if a button is pressed, while in the mouse move event, without setting a flag. I don't know.

Share this post


Link to post
Share on other sites

SDL might have a specific way to check if a button is pressed, while in the mouse move event, without setting a flag. I don't know.

It does. The state member of the SDL_MouseMotionEvent structure contains the current button state for the mouse.

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!