I Haz Codes
for |
e |
in |
event. |
get() |
if e.type |
== |
KEYDOWN |
: |
|
if e.key |
== |
K_a |
: |
The event loop in pygame is a common feature of 99% of all pygame projects and as such, is one which you must master. It will always be found in the game loop and takes the form of a for loop. Regardless of the type of event you wish to manage, the loop will always have the same structure. When dealing with keys it is important to remember that this responds to events rather than waits for them.
Note – the video was done in python 2. You will need to add brackets for python 3. The example code is written in python 3.
http://www.pygame.org/docs/ref/event.html – Types of events
http://www.pygame.org/docs/ref/key.html – Key codes used in pygame
http://openbookproject.net/thinkcs/python/english3e/pygame.html – Pygame game loop
Leave a Reply