[Author Prev][Author Next][Thread Prev][Thread Next][Author Index][Thread Index]
Re: [pygame] checking mouse button state
Hey Jake,
You're putting your 'self.player.fire()' inside the 'for' block that's processing your events.
Take your method #2 and put it outside of the 'for' block.
# code:
events = pygame.event.get()
for event in events:
# 1) this block doesn't seem to work right unless moving mouse:
(b1,b2,b3) = pygame.mouse.get_pressed()
if b1:
self.player.fire()
print 'down'
if event.type == MOUSEMOTION: pass
elif event.type == MOUSEBUTTONDOWN: self.mouse.down = True
elif event.type == MOUSEBUTTONUP: self.mouse.down = False
#else, tried: 2)
if self.mouse.down:# or True:
self.player.fire()
print 'down
-Sean
p.s. is it called a for loop? for block? eh
On Sat, Jan 10, 2009 at 7:47 PM, Jake b
<ninmonkeys@xxxxxxxxx> wrote:
I want to do a simple:
if LeftMouseDown(): fire()
But it is failing. Right now both ways I try, it only says the button is down if the mouse is moving. If I stay at the same x,y coord, it says the button not pressed(but it is).
# code:
events = pygame.event.get()
for event in events:
# 1) this block doesn't seem to work right unless moving mouse:
(b1,b2,b3) = pygame.mouse.get_pressed()
if b1:
self.player.fire()
print 'down'
#else, tried: 2)
if self.mouse.down:# or True:
self.player.fire()
print 'down'
if event.type == MOUSEMOTION: pass
elif event.type == MOUSEBUTTONDOWN: self.mouse.down = True
elif event.type == MOUSEBUTTONUP: self.mouse.down = False
I'm surprised at method #2 failing, since I never change the value of mouse.down anywhere else in the code, except those two lines above.
--
Jake