Sign in to follow this  
riruilo

How should I manage SDL mouse in a windowed FPS game?

Recommended Posts

Hi out there! How should I manage SDL mouse in a windowed FPS game? I use SDL_MOUSEMOTION event in order to move my camera, but as I use a window, I have to use SDL_WM_GrabInput(SDL_GRAB_ON) to avoid player cliking outside my window, the problem is that when mouse cursor is in a border, SDL_MOUSEMOTION data (position a relative position) is 0, so it seems my camera is frozen. Do you know how can I solve this? Thanks a lot.

Share this post


Link to post
Share on other sites
Quote:
Original post by spliter
you can use SDL_WarpMouse(x,y) to set it to the center of the screen after every mouse movement check. That way you won't have to worry about it going offscreen.


Thanks a lot.

I had to write:

SDL_EventState(SDL_MOUSEMOTION, SDL_IGNORE);
SDL_WarpMouse(SCREEN_WIDTH>>1, SCREEN_HEIGHT>>1);
SDL_EventState(SDL_MOUSEMOTION, SDL_ENABLE);

to avoid a "reverse" event.

Share this post


Link to post
Share on other sites
Quote:
Original post by Kylotan
Moving it to the middle won't be much good if you manage to move it outside of the Window during a period of slow frame rates.

Look up SDL_WM_GrabInput, see if that does the job.

EDIT: ninjaed! :(


I'm already using SDL_WM_GrabInput, but when mouse is close a corner, cannot move outside (as expected) but it does not generate events, so I have to center it.

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