I Haz Codes

Generic selectors
Exact matches only
Search in title
Search in content
Post Type Selectors
Menu
Key events

Syntax

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. 

 

Helpful links

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

Your email address will not be published. Required fields are marked *

Information