I have an event which makes me able to move a sqaure(a_block) with the mouse. However, I can't seem to change it to move if the mousebutton is constantly pressed down
if event.type == pygame.MOUSEMOTION:
mouse_position = pygame.mouse.get_pos()
a_block.set_position(mouse_position[0],mouse_position[1]
Make sure that you are going through all pygame events, because i think that you are only looking at the first event which turns out to be the mouse position when the button isn't pressed down, but when the mouse button is pressed down the first event is the button press. Here is the code snippet I used to work:
for events in pygame.event.get(): #look at all events
if events.type == pygame.MOUSEMOTION:
mouse_position = pygame.mouse.get_pos()
a_block.set_position(mouse_position[0],mouse_position[1])
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With