Appendix B. Greenfoot API

The Greenfoot API consists of five classes:


Actor methods are available to all actor subclasses.


World methods are available to the world.


Used to communicate with the Greenfoot environment itself.


Provides information about the last mouse event.


For image presentation and manipulation.

Class World

World(int worldWidth, int worldHeight, int cellSize)

Construct a new world.

void act()

Act method for the world. Called once per act round.

void addObject (Actor object, int x, int y)

Add an Actor to the world.

GreenfootImage getBackground()

Return the world’s background image.

int getCellSize()

Return the size of a cell (in pixels).

Color getColorAt(int x, int y)

Return the color at the center of the ...

Get Introduction to Programming with Greenfoot: Object–Oriented Programming in Java™ with Games and Simulations, First Edition now with O’Reilly online learning.

O’Reilly members experience live online training, plus books, videos, and digital content from 200+ publishers.