Listing 3

1  public class AnimationTest {

2

3    public static void main(

         String[] args) {

4   

5      // Enter full-screen mode

6      // and start animation

7      GraphicsSource.enterDisplayMode(

           640, 480);

8      GraphicsSource.setRenderListener(

           new FrameBuilderTest());

9      GraphicsSource.startAnimation(

           60);

10   

11     // wait for it to complete ...

12   

13     // Stop animation

14     // and exit full-screen mode

15     GraphicsSource.stopAnimation();

16     GraphicsSource.exitDisplayMode();

17   }

18 }

19

20 class FrameBuilderTest

       extends FrameBuilder {

21 

22   Image fighter, background;

23   int xf, yf, xb, yb;

24 

25   public void init() {

26     // Load the background image

27     // and foreground sprite

28     background = ImageSource

           .getImage("background.gif");

29     fighter = ImageSource

           .getImage("fighter.gif");

30   }

31 

32   public void updateState() {

33     // update position of fighter

34     // and background ...

35   }

36 

37   public boolean isBackgroundSame() {

38     if (/* ... position of background

           changed ... */)

39       return false;

40     else

41       return true;

42   }

43 

44   public void renderBackground(

         Graphics g) {

45     g.drawImage(

           background, xb, yb, null);

46   }

47 

48   public void renderBackground(

         Graphics g, int x, int y,

             int width, int height) {

49     renderBackground(g);

50   }

51 

52   public void renderForeground(

         Graphics g) {

53     drawSprite(g, fighter, xf, yf);

54   }

55 }