0

I am using SDL2 in C# to make a first person game. I want to center the mouse in the window and still collect mouse input to move the camera.

I tried SDL_WarpMouseInWindow(window, WIDTH / 2, HEIGHT / 2);, but the movement caused by this function is a mouse event, so the camera doesn't move.

Here is the relevant code:

while (running)
{
    SDL_WarpMouseInWindow(window, WIDTH / 2, HEIGHT / 2); // Problematic line

    SDL_Delay(1000 / FPS);
    PollEvents();

    Render();
}

Here is the PollEvents function:

static void PollEvents()
{
    // Check to see if there are any events and continue to do so until the queue is empty.
    while (SDL_PollEvent(out SDL_Event e) != 0)
    {
        switch (e.type)
        {
            case SDL_EventType.SDL_QUIT:
                running = false;
                break;

            case SDL_EventType.SDL_MOUSEMOTION:
                currentPlayer.Rotate(e.motion.xrel * ROTSPEED / FPS);
                break;
            
            default:
                break;
        }
    }
}
nico_qwer
  • 112
  • 10

0 Answers0