Patrick’s development blog

Getting mouse state in SDL

Posted in SDL / OpenGL by Patrick on June 23, 2009

I’ve decided to finally start a programming project after a very long break. I found the need to use mouse states when creating a Level editor for my RPG because regular events doesn’t really do what I want.

I want to add tiles fast and be able to hold the mouse key down, instead of clicking every time I want to add a tile.

Mouse states

int cx,cy;
Uint8 ms = SDL_GetMouseState(&cx, &cy);
if (ms & SDL_BUTTON(SDL_BUTTON_LEFT)) {
// the left mouse key is pressed
} else if (ms & SDL_BUTTON(SDL_BUTTON_RIGHT)) {
// the right mouse key is pressed
}

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: