Description
Now that we know how to take advantage of Greenfoot support classes, let's look at a specific class for an animated Actor. In this activity you will:
- Create a new class AnimatedActor by reusing the Greenfoot Support Class.
- Create a subclass of AnimatedActor, AnimatedMonster and show how to use its features.
- For those with artistic talent, you can replace the images provided with those of your own to create your own animated image.
- Run the scenario to see how the animation looks.
Skills you will learn include:
- Basics about a simple form of animation. This will serve as a basis before getting into more complicated approaches to animation.
- Programming constructs including arrays and string concatenation.
Basic Steps
- Start up Greenfoot.
- From the Scenario menu, select the scenario called Monsters.
- Next, create a subclass of Mover called AnimatedActor. Open the editor and cut and paste this code for the AnimatedActor class. You can learn more about AnimatedActor and other Greenfoot Support Classes in the Greenfoot Programmer's Manual and Greenfoot Support Classes. We will also go through the the code for this class in Digging Deeper.
- Create a subclass of AnimatedActor. We’ll call it AnimatedMonster. Pick an image to represent the new class.
- Open the editor for AnimatedMonster. Edit AnimatedMonster, adding a constructor, AnimatedMonster() and and the method called act(). The code for AnimatedMonster() and act can be found here. In our example, we have 4 .png images. They start with “animon”. That is, animon0.png, animon1.png, animon2.png, animon3.png.
- Compile, add AnimatedMonster objects and run the scenario. You will notice that rather than moving across their world, AnimatedMonsters stay in one position, but move or change in place. Figure out how to add code to have your monster move across the world while continuing to animate. Make sure they respond to the left and right arrow keys. Hint: Steal some code from a previous activity.
- Compile and add AnimatedMonsters to your world. If your updates are correct, you should notice that now the monsters animate while moving. Make sure they also respond to the left and right arrow keys.
- Read Greenfoot Support Classes: Digging Deeper on AnimatedActor to learn about Greenfoot support classes and the AnimatedActor class.
- Please read the following instructions for preparing your work prior to submission to this activity.
- Select Scenario -> Export. Choose Webpage (from Publish, Webpage, Application) and select a location to save the scenario as an applet (a jar file and a .html file).
- Submit the exported jar file for this activity.



