[Author Prev][Author Next][Thread Prev][Thread Next][Author Index][Thread Index]

Re: [pygame] MOUSEBUTTONDOWN question



Just making a quick game where you trace out a shape on the screen while
holding the mouse button.
Trying to check for a collision with the mouse while the button is down,
but for some reason it seems to only check for collision when the button
initially goes down, but doesn't keep checking for collision when the
mouse button is held down.
But I think it should since this is all in the event loop


if event.type is MOUSEBUTTONDOWN:
	pos=pygame.mouse.get_pos()
      mouseRect=[[pos[0],pos[1]],[5,5]]
      mouseRect=Rect(mouseRect)
      m=mouseRect.collidelist(shape)
	if m==-1:
		print "oops! Your not on the shape anymore"


You will probably want to use pygame.mouse.get_pressed()
instead of checking for a MOUSEBUTTONDOWN event.

Alternately, you could set a flag (button_is_down = 1) when
you get the MOUSEBUTTONDOWN event, and then reset
it when you get a MOUSEBUTTONUP even (button_is_down = 0)
and then test on the flag instead of the event.

_________________________________________________________________
STOP MORE SPAM with the new MSN 8 and get 2 months FREE* http://join.msn.com/?page=features/junkmail