Skip to content Skip to sidebar Skip to footer

Pygame: Mouse Specific Axis Detection

How can I detect ONLY the X axis, for example? maus_x = 0 maus_y = 0 pygame.mouse.get_pos(maus_x, maus_y) while not done: for event in pygame.event.get(): if event.type

Solution 1:

That's not how function calls work. In your code, maus_x is always 0, since nothing ever modifies it. You want:

whilenot done:
    foreventin pygame.event.get():
        ifevent.type == pygame.MOUSEMOTION:      
            mousex, mousey = pygame.mouse.get_pos()   
            if mousex < wx_coord:
                angle += 10

In fact, you probably just want to inspect the event object directly:

whilenot done:
    foreventin pygame.event.get():
        ifevent.type == pygame.MOUSEMOTION:      
            mousex, mousey = event.pos   
            if mousex < wx_coord:
                angle += 10

Or better yet:

whilenot done:
    foreventin pygame.event.get():
        ifevent.type == pygame.MOUSEMOTION:      
            relx, rely = event.rel   
            if relx != 0:  # x movement
                angle += 10

Post a Comment for "Pygame: Mouse Specific Axis Detection"