Book Image

Creative Greenfoot: RAW

By : Michael Haungs
Book Image

Creative Greenfoot: RAW

By: Michael Haungs

Overview of this book

Table of Contents (17 chapters)
Creative Greenfoot
Credits
About the Author
About the Reviewers
www.PacktPub.com
Preface
Index

Image swapping and movement


Image swapping is the age-old technique for animating. Perhaps as a child, you drew a stick figure in the corner of a pad of paper and slightly changed it on every succeeding page. When you rapidly flipped through the pages, your stick figure came to life. Figure 2 shows my attempt at this type of animation.

Figure 1: This shows old-school stick figure animation

In Greenfoot, we are going to animate actors by rapidly switching between images and achieve the same effect as the paper animation shown in Figure 1. We will learn how to use Greenfoot's setImage() method to do this.

Using setImage()

When we create a new Actor in Greenfoot by subclassing from the Actor class, or one of our subclasses of Actor, Greenfoot prompts us to enter in the name of our new class and to select an image for it. Greenfoot also allows us to dynamically set the image of our Actor objects while the scenario is running, using the method setImage()provided by Greenfoot's Actor class. The following...