The Python Game Book

code games. learn Python.

User Tools

Site Tools


en:pygame:step016

Differences

This shows you the differences between two versions of the page.

Link to this comparison view

Both sides previous revision Previous revision
Next revision Both sides next revision
en:pygame:step016 [2014/01/09 11:07]
127.0.0.1 external edit
en:pygame:step016 [2020/05/03 21:04]
horst ↷ Links adapted because of a move operation
Line 62: Line 62:
 ==== changing layers ==== ==== changing layers ====
  
-The cool things about layers is: you can change them even at runtime, to place sprites more in the foreground or more in the background (see code example below). The **change_layer** method does exaclty that. Important: you need only to change the layer of the LayeredUpdates-group that actually draws the sprites on the screen. In the code example below, this is the **allgroup**. (Special thanks to [[en:resources:people:gummbum:start|Gummbum]] for helping me out here). Because i want only to change the layer of the **Bird** sprites and their **Lifebar** sprites i loop over all sprites in the groups **birdgroup** and **bargroup**. Each Bird sprite is a member of the allgroup as well as of the birdgroup. Each Lifebar sprite is a member of the allgroup as well as of the bargroup.+The cool things about layers is: you can change them even at runtime, to place sprites more in the foreground or more in the background (see code example below). The **change_layer** method does exaclty that. Important: you need only to change the layer of the LayeredUpdates-group that actually draws the sprites on the screen. In the code example below, this is the **allgroup**. (Special thanks to [[en:secret:people:gummbum:start|Gummbum]] for helping me out here). Because i want only to change the layer of the **Bird** sprites and their **Lifebar** sprites i loop over all sprites in the groups **birdgroup** and **bargroup**. Each Bird sprite is a member of the allgroup as well as of the birdgroup. Each Lifebar sprite is a member of the allgroup as well as of the bargroup.
  
 <code python> <code python>
en/pygame/step016.txt · Last modified: 2020/05/15 22:50 by horst