How should I manage SDL mouse in a windowed FPS game?
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.
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.
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.
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! :(
Look up SDL_WM_GrabInput, see if that does the job.
EDIT: ninjaed! :(
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.
This topic is closed to new replies.
Advertisement
Popular Topics
Advertisement