[Author Prev][Author Next][Thread Prev][Thread Next][Author Index][Thread Index]
Re: [pygame] Struggling with mouse input
Dave Mikesell wrote:
Pygame newbie here. I'm writing what could be considered an
Asteroids-type clone (actually, it's an Odyssey II UFO! clone but nobody
probably remembers OII) and want to turn my ship using the mouse. Is
there a standard way to do this, or perhaps a sample I could look at?
Basically, I'm catching MOUSEMOTION events and comparing the X values from
the current and previous frames to determine which direction to turn.
So I guess what I am asking is, what are best practices for moving a
player/object using the mouse?
There should be nothing inherently jerky with the mouse motion. But it
is hard to guess what is causing the trouble. I would suspect the
drawing of the ship, but it sounds like you have a working case with the
keyboard.
Inside your event handling code you shouldn't need much more than this.
for event in pygame.event.get():
if event.type == pygame.MOUSEMOTION:
shipAngle += event.rel[0] * 0.5
Then when you render just apply the appropriate shipAngle rotation.