| Deutsch English |
![]()
YOU LEARN HERE... |
how the game characters can change their appearance during movement. The user must have the impression that the game characters are eating, running, swimming, etc. To make this as easy as possible, you can assign several sprites to an actor, only one of which is visible at a time. The number of sprites is specified as a parameter when the actor is created. The individual sprites must be saved with an index number. |
EXAMPLES |
Program: # Gg4.py from gamegrid import * # ------------- class Pacman --------------------------- class Pacman(Actor): def __init__(self): Actor.__init__(self, "sprites/pacman.gif", 2) def act(self): self.move() self.showNextSprite() if self.getX() == 9: self.turn(90) self.setHorzMirror(True) if self.getX() == 0: self.turn(270) self.setHorzMirror(False) # ---------- main --------------------------------- makeGameGrid(10, 10, 60, Color.red) paki = Pacman() addActor(paki, Location(0, 0)) show() doRun()
Program: # Gg4a.py from gamegrid import * # ------------- class Head --------------------------- class Head(Actor): def __init__(self): Actor.__init__(self, "sprites/head.png", 3) def act(self): self.move() self.showNextSprite() if (self.getX() > 500) or (self.getX() < 95): self.turn(180) # ---------- main ---------------------------- makeGameGrid(600, 600, 1, Color.yellow) addActor(Head(), Location(135, 180)) addActor(Head(), Location(300, 450)) show() doRun() |
REMEMBER YOU... |
| To animate an actor during movement, you can assign several sprites to it, which are visible alternately. You specify the number of sprites as a parameter when creating the actor. With showNextSprite(), the images are displayed in sequence; after the last image, the first image appears again. |
TO SOLVE BY YOURSELF |
|
||||||||
|
||||||||
| 2. |
|
|||||||
|
![]()