ste3e
ste3e

Reputation: 1045

SDL2 mouse grab is not working

With SDL 1.2 I was using SDL_WM_GrabInput to center the (hidden) mouse on screen. This gave me unlimited turning freedom for a first person shooter. SDL2 no longer provides this function but has SDL_SetWindowGrab. This does not seem to be repositioning the mouse to the center of the screen after each loop (event read). I can turn the player around only 1 and a half times before the mouse has hit the edge of the window and will no longer produce xrel values. Is this a bug or is there another function I should be using?

Upvotes: 5

Views: 6361

Answers (1)

genpfault
genpfault

Reputation: 52123

Give SDL_SetRelativeMouseMode() and SDL_GetRelativeMouseState() a try.

Alternatively recenter the mouse each frame yourself with SDL_WarpMouseInWindow().

Upvotes: 4

Related Questions