[SDL] Using mouse movement in SDL 1.2 even if cursor moves beyond

MBrening micah.brening at gmail.com
Fri Dec 31 11:49:54 PST 2010


I'd suggest having a simple bit flag (int, bool, whatever)

if (CursorAtEdge)
  RepositionedCursor = 1
  SDL_WarpMouse()

And then

if (RepositionedCursor != 1)
    /* Handle Movement*\

when you are done processing events, you can set RepositionedCursor to 0 or false.  That way you don't get the glitch, and it's just one extra variable to track.


David Bruce wrote:
> Hi,
> 
> On Thu, Dec 30, 2010 at 5:00 PM, Justin Coleman <jmcoleman at gmail.com> wrote:
> 
> > You'll need to set the mouse position to the center of the screen
> > every time you go through your main loop, that way you'll continue to
> > receive motion events (as it will never hit the edge of the screen).
> > 
> 
> Well, looking through the docs, I found the following.
> 
> "If the cursor is hidden (SDL_ShowCursor(0)) and the input is grabbed
> (SDL_WM_GrabInput(SDL_GRAB_ON)), then the mouse will give relative
> motion events even when the cursor reaches the edge of the screen.
> This is currently only implemented on Windows and Linux/Unix-alikes."
> 
> So I guess I'm OK except for OS-X, in which case I can reposition the
> mouse as you recommend.  I take it that means using SDL_WarpMouse()?
> The only problem seems to be that the repositioning itself generates a
> mouse motion event every frame, which is making the control behave a
> little erratically.  Is there a clean, reliable way to ignore the
> events generated by SDL_WarpMouse() without risking losing other
> events?  Alternatively, I could only do the reset-to-center when the
> cursor hits the edge of the screen, rather than every frame, which at
> most should cause an infrequent "hiccup".
> 
> Thanks,
> 
> David Bruce
> _______________________________________________
> SDL mailing list
> SDL at lists.libsdl.org
> http://lists.libsdl.org/listinfo.cgi/sdl-libsdl.org





-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.libsdl.org/pipermail/sdl-libsdl.org/attachments/20101231/0984304c/attachment-0007.htm>


More information about the SDL mailing list