Sign in to follow this  
chosenkill6

SDL mouse dragging

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
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 [b]true[/b]) 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 [b]false[/b]. 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
[quote name='AverageMidget' timestamp='1318560019' post='4872393']
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.
[/quote]
It does. The state member of the [url=http://www.libsdl.org/docs/html/sdlmousemotionevent.html]SDL_MouseMotionEvent[/url] structure contains the current button state for the mouse.

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this