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
Previous revision
Last 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:35]
horst ↷ Links adapted because of a move operation
Line 3: Line 3:
 ^ [[:en:pygame:step015| ← previous]] ^ [[en:pygame:start| ↑ Overview]] ^ [[:en:pygame:step017| → next ]] ^ ^ [[:en:pygame:step015| ← previous]] ^ [[en:pygame:start| ↑ Overview]] ^ [[:en:pygame:step017| → next ]] ^
 ====== gameplay ====== ====== gameplay ======
-{{:en:part2:part2step016.jpg?400 |screenshot of layers}}+{{part2:part2step016.jpg?400 |screenshot of layers}}
  
 The source code example below is not much of a game, but it demonstrates the uses of layers for sprites and [[wp>Parallax_scrolling]] (the mountains). Also, you can hide penguins behind blocks and mountains. The source code example below is not much of a game, but it demonstrates the uses of layers for sprites and [[wp>Parallax_scrolling]] (the mountains). Also, you can hide penguins behind blocks and mountains.
Line 10: Line 10:
 **Trivia:**  **Trivia:** 
  
-[[http://www.arcade-museum.com/game_detail.php?game_id=8747|{{ :en:part2:moon-patrol.png|screenshot of moon-patrol. Picture from http://www.arcade-museum.com/game_detail.php?game_id=8747}}]]+[[http://www.arcade-museum.com/game_detail.php?game_id=8747|{{ part2:moon-patrol.png|screenshot of moon-patrol. Picture from http://www.arcade-museum.com/game_detail.php?game_id=8747}}]]
  
 According to wikipedia, Parallax scrolling was first introduced to computer games by the arcade game [[wp>Moon_Patrol]] 1982. The mountains (and in higher levels, futuristic buildings) moved at different speed to create the illusion of a [[wp>Side-scroller|side-scrolling computer game]]. According to wikipedia, Parallax scrolling was first introduced to computer games by the arcade game [[wp>Moon_Patrol]] 1982. The mountains (and in higher levels, futuristic buildings) moved at different speed to create the illusion of a [[wp>Side-scroller|side-scrolling computer game]].
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>
Line 240: Line 240:
 ^  file  ^  in folder  ^  download  ^ ^  file  ^  in folder  ^  download  ^
 |  [[https://github.com/horstjens/ThePythonGameBook/raw/master/pygame/016_layers.py|016_layers.py]]  |  ''pygame''  |  Download the whole Archive with all files from Github:  \\  https://github.com/horstjens/ThePythonGameBook/archives/master  | |  [[https://github.com/horstjens/ThePythonGameBook/raw/master/pygame/016_layers.py|016_layers.py]]  |  ''pygame''  |  Download the whole Archive with all files from Github:  \\  https://github.com/horstjens/ThePythonGameBook/archives/master  |
-|  [[https://github.com/horstjens/ThePythonGameBook/blob/master/pygame/data/babytux.png|babytux.png]] \\ [[https://github.com/horstjens/ThePythonGameBook/blob/master/pygame/data/babytux.png|{{:en:part2:babytux.png|babytux.png}}]]  |  ''pygame/data''  |  :::  | +|  [[https://github.com/horstjens/ThePythonGameBook/blob/master/pygame/data/babytux.png|babytux.png]] \\ [[https://github.com/horstjens/ThePythonGameBook/blob/master/pygame/data/babytux.png|{{part2:babytux.png|babytux.png}}]]  |  ''pygame/data''  |  :::  | 
-|  [[https://github.com/horstjens/ThePythonGameBook/blob/master/pygame/data/babytux_neg.png|babytux_neg.png]] \\ [[https://github.com/horstjens/ThePythonGameBook/blob/master/pygame/data/babytux_neg.png|{{:en:part2:babytux_neg.png|babytux_neg.png}}]]  |  ''pygame/data''  |  :::  |+|  [[https://github.com/horstjens/ThePythonGameBook/blob/master/pygame/data/babytux_neg.png|babytux_neg.png]] \\ [[https://github.com/horstjens/ThePythonGameBook/blob/master/pygame/data/babytux_neg.png|{{part2:babytux_neg.png|babytux_neg.png}}]]  |  ''pygame/data''  |  :::  |
 |  [[https://github.com/horstjens/ThePythonGameBook/blob/master/pygame/data/claws.ogg|claws.ogg]]  \\  from Battle of Wesnoth  |  ''pygame/data''  |  :::  | |  [[https://github.com/horstjens/ThePythonGameBook/blob/master/pygame/data/claws.ogg|claws.ogg]]  \\  from Battle of Wesnoth  |  ''pygame/data''  |  :::  |
  
en/pygame/step016.txt · Last modified: 2020/05/15 22:50 by horst