Jump to content
  • Advertisement
Sign in to follow this  
riruilo

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

This topic is 3047 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

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
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.

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
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! :(

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
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

Participate in the game development conversation and more when you create an account on GameDev.net!

Sign me up!