[SDL] SDL_SetRelativeMouseMode Starting Position

Naith Danielane85 at hotmail.com
Mon Sep 1 12:29:48 PDT 2014


What I'm doing when I want to center the mouse pointer in the window and also trap it inside the window is by first using this function:


Code:
			
	SDL_WarpMouseInWindow(TheWindow, WINDOW_WIDTH / 2, WINDOW_HEIGHT / 2);





Then I use this function to trap the mouse pointer inside the window:


Code:

	SDL_SetWindowGrab(TheWindow, SDL_TRUE);





Note that the mouse pointer will still be visible when using this function.
If you want to hide the mouse pointer you can use this function to hide it:


Code:

	SDL_ShowCursor(0);





The mouse pointer should, if you've made everything right, be centered and trapped inside the window when you're starting the program.

If you would like to center the mouse pointer all the time even if the mouse is moved, use SDL_WarpMouseInWindow each frame to center the mouse pointer.




-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.libsdl.org/pipermail/sdl-libsdl.org/attachments/20140901/3b21a82d/attachment-0002.htm>


More information about the SDL mailing list