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

Started by
5 comments, last by Kylotan 14 years, 2 months ago
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.
I've seen things you people wouldn't believe. Attack ships on fire off the shoulder of Orion. I watched C-beams glitter in the dark near the Tannhauser gate. All those moments will be lost in time, like tears in rain. Time to die.
Advertisement
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.
I've seen things you people wouldn't believe. Attack ships on fire off the shoulder of Orion. I watched C-beams glitter in the dark near the Tannhauser gate. All those moments will be lost in time, like tears in rain. Time to die.
see SDL_WM_GrabInput
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! :(
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.
I've seen things you people wouldn't believe. Attack ships on fire off the shoulder of Orion. I watched C-beams glitter in the dark near the Tannhauser gate. All those moments will be lost in time, like tears in rain. Time to die.
Interesting. :)

This topic is closed to new replies.

Advertisement