Sign in to follow this  
danDemon

SDL. How to disable mouse ?

Recommended Posts

danDemon    122
My program lags when I move the pointer around the screen, so I need to disable it. Pretty common problem, but the usual answer is: SDL_ShowCursor(0); which doesn't work for me because it only hides it, while I need my game to ignore\disable any mouse input so it won't be counted in the SDL_PollEvent. Is that possible ?

Share this post


Link to post
Share on other sites
Kambiz    758
I have never noticed such lags, how does your event loop looks like?
Are you handling all events every frame?

// main loop
while(1){
// event loop
while(SDL_PollEvent(&event)) {
...
}
...
}

Share this post


Link to post
Share on other sites
danDemon    122
Yes,

while(gameRunning)
{
//draw sprite here

if(SDL_PollEvent(&event))
{
if(event.type == SDL_QUIT)
gameRunning=false;

if(event.type == SDL_KEYDOWN)
{
keyHold[event.key.keysym.sym] = true;
}

if(event.type == SDL_KEYUP)
{
keyHold[event.key.keysym.sym] = false;
}

}

//keyHold[] array stores values for every key, so the character
//moves constantly on KEYDOWN and stops on KEYUP.

if(keyHold[SDLK_ESCAPE])
gameRunning = false;

if( keyHold[SDLK_LEFT] )
{
Player->moveLeft();
}
if( keyHold[SDLK_UP] )
{
Player->moveUp();
}
if( keyHold[SDLK_DOWN] )
{
Player->moveDown();
}
if( keyHold[SDLK_RIGHT] )
{
Player->moveRight();
}

}

Share this post


Link to post
Share on other sites
Kambiz    758
Quote:
Original post by danDemon
Yes. I use input method similar to the one posted in Aaron's tutorial:

http://www.aaroncox.net/tutorials/2dtutorials/sdlkeyboard.html


That tutorial is checking just one event per frame:

if (SDL_PollEvent(&event)) ...


notice that I had a while instead of the if.

Share this post


Link to post
Share on other sites
danDemon    122
Quote:
Original post by Kambiz
Quote:
Original post by danDemon
Yes. I use input method similar to the one posted in Aaron's tutorial:

http://www.aaroncox.net/tutorials/2dtutorials/sdlkeyboard.html


That tutorial is checking just one event per frame:

if (SDL_PollEvent(&event)) ...


notice that I had a while instead of the if.


Damn I would never suspect simple operation would fix the problem, thanks a LOT man! :)

Share this post


Link to post
Share on other sites
dmail    116
Quote:
Original post by danDemon
while I need my game to ignore\disable any mouse input so it won't be counted in the SDL_PollEvent.

Is that possible ?

This is only posted for completeness of the thread, as the OP's problem is fixed.
Yes if this is really what you want. You can set up an event filter in which you can decide if to allow the event onto the queue. This enables you to switch the mouse events on and off at your will. There is a special note to take into consideration, this being that mouse wheel events are sent as button events. Alternately if you never want to get the events then simply set the state to ignore using SDL_EventState.

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