logame team mailing list archive
-
logame team
-
Mailing list archive
-
Message #00029
Re: Keyboard Problems
That's a good idea! It has to be adapted a bit as we have only two
directions to walk to, but it should solve the missing key event issue.
I saw that the release events are coming properly.
That's coming handy as I wanted to refactor the keyup/keydown handling
anyway, as it's a bit smelly. :-)
I would suggest that I change the key handling together with the general
keyup/keydown handling as it's lying very close together, but I wouldn't
insist on that. :-)
Ben
PS: Thanks btw for adding the yaml installation checks. I sometimes forget
that not every user can determine which package is missing from only the
stacktrace. :-) I added you to the Credits file as jezra, if you want to be
mentioned there in a different manner don't hesitate to change it. :-)
2009/10/5 jezra lickter <jezra@xxxxxxxxx>
> On Mon, 05 Oct 2009 22:14:29 +0100
> Paul Elms <paul@xxxxxxxxxxxxxx> wrote:
>
> > Hi Ben,
> >
> > My keyboard will register 3 keys at once, ie: left, up and fire and
> > all three keypresses are registered by pygame (I get the logging
> > output from 3 keys). I have also read that keyboards can only handle
> > so many key presses at one time and it varies from keyboard to
> > keyboard, so I think we will have to live with it.
> >
> > I don't really know how event handling works in pygame, but I also get
> > what you describe, holding down one key and then tapping another stops
> > the first key. It sounds like the keyup event from the tap blocks the
> > ongoing keydown event, but I am only guessing. I'll have another look
> > at event handling tomorrow, when I am less tired :)
> >
> > Paul
> >
> >
> > _______________________________________________
> > Mailing list: https://launchpad.net/~logame<https://launchpad.net/%7Elogame>
> > Post to : logame@xxxxxxxxxxxxxxxxxxx
> > Unsubscribe : https://launchpad.net/~logame<https://launchpad.net/%7Elogame>
> > More help : https://help.launchpad.net/ListHelp
> >
>
> A possible solution is to set four directional movement variables in
> the sprite class, possibly in an array, and then loop through the
> variables and move as necessary. Something along the lines of
> class sprite:
> speed = 5
> gravity_speed = 1
> movement = (0,0,0,0) # up,right,down,left
>
> def move:
> if self.movement[0]==1:
> self.y-=speed
> if self.movement[1]==1:
> self.x+=speed
> if self.movement[2]==1:
> self.y+=speed
> if self.movement[3]==1:
> self.x-=speed
> #move for gravity
> self.y+=gravity_speed
>
> And then from the keyboard commands the RIGHT_ARROW keydown sets the
> movement[1] to 1 and the RIGHT_ARROW keyup set the movement[1] to 0.
> Actually, booleans would probably work a bit better.
>
> I have recently written some Vala code to do this using SDL, and I could
> port the code to Python if anyone is interested.
>
> jezra
>
>
>
>
>
>
>
>
> _______________________________________________
> Mailing list: https://launchpad.net/~logame<https://launchpad.net/%7Elogame>
> Post to : logame@xxxxxxxxxxxxxxxxxxx
> Unsubscribe : https://launchpad.net/~logame<https://launchpad.net/%7Elogame>
> More help : https://help.launchpad.net/ListHelp
>
References