reset password
Author Message
jcalilu
Posts: 20
Posted 14:19 Apr 26, 2016 |

When I add a new sprite by pressing down a key, sometimes I get 1 (by pressing the key really fast and lightly) but mostly 2 sprites (regular pressing) added to the screen. Is there a way to add only 1 sprite after the key has been pressed down once?

I've tried looking at the document for key in Pygame but could not get any idea how to do this.

dbravoru
Posts: 60
Posted 14:24 Apr 26, 2016 |

Maybe it has to do with how when you hold a key down, it repeats the key. Try checking for event.type == KEYUP instead of KEYDOWN, since you only lift up a key once, regardless if you held it down or not. 

Last edited by dbravoru at 14:24 Apr 26, 2016.
jcalilu
Posts: 20
Posted 14:39 Apr 26, 2016 |
dbravoru wrote:

Maybe it has to do with how when you hold a key down, it repeats the key. Try checking for event.type == KEYUP instead of KEYDOWN, since you only lift up a key once, regardless if you held it down or not. 

Will try that, thanks!

baghumyan
Posts: 8
Posted 15:08 Apr 28, 2016 |

I had the same problem and this is what I did: instead of KEYUP I set "whatever key" = False. Basically I set the key to be equal False manually instead of KEYUP and it fixed it