All I need is a boolean that is true if the left mouse button is down and false if the left mouse button is up.
I can't find it.
Please Help!
SDL Mouse States
Moderator: Coders of Rage
-
- Chaos Rift Regular
- Posts: 198
- Joined: Thu Mar 26, 2009 8:42 pm
- Current Project: My Engine
- Programming Language of Choice: C++
SDL Mouse States
My first game: http://donsvoice.com/randomdever/Duck%2 ... 01.0.0.zip
My second game: http://donsvoice.com/randomdever/Space%20Invaders.zip
My third game: http://donsvoice.com/randomdever/BreakOut!.zip
My second game: http://donsvoice.com/randomdever/Space%20Invaders.zip
My third game: http://donsvoice.com/randomdever/BreakOut!.zip
-
- Chaos Rift Demigod
- Posts: 991
- Joined: Thu Nov 13, 2008 3:16 pm
- Current Project: Elysian Shadows
- Favorite Gaming Platforms: Amiga, PSOne, NDS
- Programming Language of Choice: C++
- Location: Sweden
Re: SDL Mouse States
I can't give you an example by ready-to-go code, but you need to track the mouse states, something like this:
Code: Select all
bool lmbPressed = false; // lmb == left mouse button
if( g_Event.type == SDL_MOUSEBUTTONDOWN && SDL_BUTTON(SDL_GetMouseState(NULL,NULL)) == SDL_BUTTON_LEFT ) {
lmbPressed = true;
}
if( g_Event.type == SDL_MOUSEBUTTONUP ) {
lmbPressed = false;
}
- M_D_K
- Chaos Rift Demigod
- Posts: 1087
- Joined: Tue Oct 28, 2008 10:33 am
- Favorite Gaming Platforms: PC
- Programming Language of Choice: C/++
- Location: UK
Re: SDL Mouse States
Code: Select all
struct Mouse
{
int dx, dy;
int oldX, oldY;
unsigned int buttons;
unsigned int oldButtons;
};
Code: Select all
SDL_PumpEvents();
mouse.oldButtons = mouse.buttons;
mouse.oldX = mouse.dx;
mouse.oldY = mouse.dy;
mouse.buttons = SDL_GetMouseState(&mouse.dx, &mouse.dy);
Code: Select all
bool mouseDown(int button)
{
return currMouse(button) && (!oldMouse(button));
}
bool mouseStillDown(int button)
{
return currMouse(button) && (oldMouse(button));
}
where currMouse and oldMouse are defines:
Code: Select all
#define currMouse(x) ((mouse.buttons&SDL_BUTTON(x)) != 0)
#define oldMouse(x) ((mouse.oldButtons&SDL_BUTTON(x)) != 0)
Gyro Sheen wrote:you pour their inventory onto my life
IRC wrote: <sparda> The routine had a stack overflow, sorry.
<sparda> Apparently the stack was full of shit.
-
- Chaos Rift Regular
- Posts: 198
- Joined: Thu Mar 26, 2009 8:42 pm
- Current Project: My Engine
- Programming Language of Choice: C++
Re: SDL Mouse States
OK I tried all of your solutions and they didn't fully work.
The only time the thang would update was when I triggered an event.
So I thought OK maybe I put the update function in the while loop that handles events.
I checked and it wasn't in there.
After toying around for 30 minutes I realized that the functions were reversed.
I had made the update() code handle events and the check() code handle the thangs update.
So in essence I had my events updated in the logic section and my logic updated in my events section.
Anyways thank for all of your solutions.
The only time the thang would update was when I triggered an event.
So I thought OK maybe I put the update function in the while loop that handles events.
I checked and it wasn't in there.
After toying around for 30 minutes I realized that the functions were reversed.
I had made the update() code handle events and the check() code handle the thangs update.
So in essence I had my events updated in the logic section and my logic updated in my events section.

Anyways thank for all of your solutions.
My first game: http://donsvoice.com/randomdever/Duck%2 ... 01.0.0.zip
My second game: http://donsvoice.com/randomdever/Space%20Invaders.zip
My third game: http://donsvoice.com/randomdever/BreakOut!.zip
My second game: http://donsvoice.com/randomdever/Space%20Invaders.zip
My third game: http://donsvoice.com/randomdever/BreakOut!.zip