70 likes | 355 Views
Animating Actors In Greenfoot. To create an animated actor, you must first: Create a series of images. The images must begin with the same name FOLLOWED by the number for which order you want the images animated. For example:.
E N D
To create an animated actor, you must first: • Create a series of images. • The images must begin with the same name FOLLOWED by the number for which order you want the images animated. • For example:
Once you have your images, you must place them in the “images” folder of your scenario. • You will then need to create subclasses of your Actor class. • Create a Mover class The support file is on the Greenfoot website. • Create an AnimatedActor class The support file is on the Greenfoot website.
You must copy the code from those support classes into the code for the Mover and AnimatedActor classes. • After you do this add your class you wish to animate as a subclass to the AnimatedActor class. Ex:
Add the following code to your class: • Ex: This is the filename extension of your files. This is the number of files you are animating. This is the first part of the name of your image files.
public class Bullet extends AnimatedActor { public Bullet( ) { super("bullet", ".png", 3); } public void act( ) { super.act( ); } } • What does “super” mean? • Super calls the superclass’ constructor. • Also, the super keyword gives you access to the superclass’ methods and variables. • In this example, AnimatedActor is the superclass of the Bullet class.