Advertisement

First person shooter C# SdlDotnet mouse input.

Started by July 24, 2018 12:08 PM
3 comments, last by Udovis Devoh 6 years, 1 month ago

Hi, I developed a FPS game about 8 years ago using SDLDotNet. It worked fine until recently. Something must have changed in some builtin API (it could be my Windows version).

My FPS works by hiding the mouse cursor and re-centering it at each frame (so the cursor doesn't leave the window), however, when I recenter the mouse cursor, it fires an even that moves the mouse in the opposite direction, so my movement is cancelled. I tried many things like ignoring the event when the X and Y are the same as the center position but it didn't work. It seems that re-centering the mouse cursor is done on multiple intermediate frames.

Could I get low level handle on the mouse motion instead? Are there other tricks I could use? Here's a sample of my code:



public void OnMouseMotion(object sender, MouseMotionEventArgs args)
{
  short relativeX = (short)(inputState.CurrentX - args.X);
  short relativeY = (short)(inputState.CurrentY - args.Y);

  inputState.CurrentX = args.X;
  inputState.CurrentY = args.Y;

  inputState.MouseMotionX = relativeX;
  inputState.MouseMotionY = relativeY;

  Cursor.Position = screenCenterPosition;
}

 

[quote]Firemen get paid even if there's no fire, and that's a good thing -me[/quote]

Have you tried the SDL_WarpMouseInWindow function or the SDL_WarpMouseGlobal function? I am not familiar with SDLDotNet and the documentation is a little sparse, but it should have one of those (or even SDL_WarpMouse?). You will probably want to use the SDL_WarpMouseInWindow.

 

Here are the links to the main documentation:

https://wiki.libsdl.org/SDL_WarpMouseInWindow

https://wiki.libsdl.org/SDL_WarpMouseGlobal

Advertisement

Thank you but the closest thing to WarpMouseInWindow in SdlDotNet seems to be Mouse.Position. Same behavior as Cursor.Position so it doesn't help. I might try something low level instead.

[quote]Firemen get paid even if there's no fire, and that's a good thing -me[/quote]

I tried using https://blogs.msdn.microsoft.com/toub/2006/05/03/low-level-mouse-hook-in-c/ but I'm still having the exact same problem. I cannot capture mouse movement outside the screen so if I try to force to recenter the cursor, I send a mouse event that cancels the movement I was trying to make.

[quote]Firemen get paid even if there's no fire, and that's a good thing -me[/quote]

This topic is closed to new replies.

Advertisement