S
S
Sergey Minakov2020-12-26 18:22:46
pygame
Sergey Minakov, 2020-12-26 18:22:46

How to fix the cursor to the center and receive the MOUSEMOTION event?

I'm making a 3D game in pygame using ray casting. It is necessary to make a rotation on the movement of the mouse. To do this, I catch the MOUSEMOTION event, add event.rel[0] to the player's rotation angle, and move the cursor back to the center.

for event in pygame.event.get():
    if event.type == pygame.MOUSEMOTION:
        pygame.mouse.set_pos(WIDTH // 2, HEIGHT // 2)
        player.vx += event.rel[0] * SENSITIVITY

The problem is that moving the cursor to the center triggers a new MOUSEMOTION event whose rel attribute is equal to the negative rel of the previous move event.
How to fix the cursor in the center so that unnecessary MOUSEMOTION events are not called?

Answer the question

In order to leave comments, you need to log in

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question