SDL mouse dragging

Started by
1 comment, last by SiCrane 12 years, 6 months ago
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
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.

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.

This topic is closed to new replies.

Advertisement