Sie sind auf Seite 1von 4

Greenfoot API Version 2.0.

2
The Greenfoot API consists of six classes:

World

World methods are available to the world.

Greenfoot

Used to communicate with the Greenfoot environment itself. Provide information about the last mouse event.

GreenfootImage

For image presentation and manipulation. For controlling sound playback.

Actor

Actor methods are available to all actor subclasses.

MouseInfo

GreenfootSound

Class World
World(intworldWidth, intworldHeight, intcellSize) void act() void addObject(Actorobject, intx, inty) GreenfootImage getBackground() int getCellSize() Color getColorAt(intx, inty) int getHeight() List getObjects(Classcls) List getObjectsAt(intx, inty, Classcls) int getWidth() int numberOfObjects() void removeObject(Actorobject) void removeObjects(Collectionobjects) void repaint() void setActOrder(Class... classes) void setBackground(GreenfootImageimage) void setBackground(Stringfilename) void setPaintOrder(Class... classes) void started() void stopped() Construct a new world. Act method for the world. Called once per act round. Add an Actor to the world. Return the world's background image. Return the size of a cell (in pixels). Return the color at the center of the cell. Return the height of the world (in number of cells). Get all the objects in the world. Return all objects at a given cell. Return the width of the world (in number of cells). Get the number of actors currently in the world. Remove an object from the world. Remove a list of objects from the world. Repaint the world. Set the act order of objects in the world. Set a background image for the world. Set a background image for the world from an image le. Set the paint order of objects in the world. Called by the Greenfoot system when execution has started. Called by the Greenfoot system when execution has stopped.

Greenfoot API version 2.0.2 is supported since Greenfoot version 2.0.1.

Greenfoot API Version 2.0.2

Class Actor
Actor() void act() protected void addedToWorld(Worldworld) GreenfootImage getImage() protected List getIntersectingObjects (Classcls) protected List getNeighbours (intdistance, booleandiagonal, Classcls) Construct an Actor. The act method is called by the Greenfoot framework to give objects a chance to perform some action. This method is called by the Greenfoot system when the object has been inserted into the world. Returns the image used to represent this Actor. Return all the objects that intersect this object. Return the neighbours to this object within a given distance.

protectedList getObjectsAtOffset(intdx, Return all objects that intersect the given location (relative intdy, Classcls) to this object's location). protected List getObjectsInRange(intr, Classcls) protectedActor getOneIntersectingObject (Classcls) protectedActor getOneObjectAtOffset (intdx, intdy, Classcls) int getRotation() World getWorld() int getX() int getY() Return all objects within range 'r' around this object. Return an object that intersects this object. Return one object that is located at the specied cell (relative to this objects location). Return the current rotation of the object. Return the world that this object lives in. Return the x-coordinate of the object's current location. Return the y-coordinate of the object's current location.

protectedboolean intersects(Actorother) Check whether this object intersects another given object. void setImage(GreenfootImageimage) void setImage(Stringfilename) void setLocation(intx, inty) void setRotation(introtation) Set the image for this object to the specied image. Set an image for this object from an image le. Assign a new location for this object. Set the rotation of the object.

Class GreenfootImage
GreenfootImage(GreenfootImageimage) GreenfootImage(intwidth, intheight) GreenfootImage(Stringfilename) GreenfootImage(Stringstring, intsize, Colorforeground, Colorbackground) void clear() Create a GreenfootImage from another GreenfootImage. Create an empty (transparent) image with the specied size. Create an image from an image le. Create an image with the given string drawn as text using the font size, foreground color and background color. Clear the image. (continued next page)

Greenfoot API Version 2.0.2

Class GreenfootImage
void drawImage(GreenfootImageimage, intx, inty) void drawLine(intx1, inty1, intx2, inty2) void drawOval(intx, inty, intwidth, intheight) void drawPolygon(int[]xPoints, int []yPoints, intnPoints) void drawRect(intx, inty, intwidth, intheight) void drawString(Stringstring, intx, inty) void fill() void fillOval(intx, inty, intwidth, intheight) void fillPolygon(int[]xPoints, int[]yPoints, intnPoints) void fillRect(intx, inty, intwidth, intheight) BufferedImage getAwtImage() Color getColor() Color getColorAt(intx, inty) Font getFont() int getHeight() int getTransparency() int getWidth() void mirrorHorizontally() void mirrorVertically() void rotate(intdegrees) void scale(intwidth, intheight) void setColor(Colorcolor) Draws the given Image onto this image. Draw a line, using the current drawing color, between the points (x1,!y1) and (x2,!y2). Draw an oval bounded by the specied rectangle with the current drawing color. Draws a closed polygon dened by arrays of x and y coordinates. Draw the outline of the specied rectangle. Draw the text given by the specied string, using the current font and color. Fill the entire image with the current drawing color. Fill an oval bounded by the specied rectangle with the current drawing color. Fill a closed polygon dened by arrays of x and y coordinates. Fill the specied rectangle. Returns the BufferedImage that backs this GreenfootImage. Return the current drawing color. Return the color at the given pixel. Get the current font. Return the height of the image. Return the transparency of the image (range 0 to 255). Return the width of the image. Mirror the image horizontally (ip around the x-axis). Mirror the image vertically (ip around the y-axis). Rotates this image around the center. Scales this image to a new size. Set the current drawing color.

void setColorAt(intx, inty, Colorcolor) Sets the color at the given pixel to the given color. void setFont(Fontf) void setTransparency(int t) String toString() Set the current font. Set the transparency of the image (range 0 to 255). Return a string representation of this image.

Greenfoot API Version 2.0.2

Class Greenfoot
Greenfoot() staticvoid delay(int time) staticString getKey() static MouseInfo getMouseInfo() staticint getRandomNumber(intlimit) staticboolean isKeyDown(StringkeyName) staticboolean mouseClicked(Object obj) staticboolean mouseDragEnded(Object obj) staticboolean mouseDragged(Object obj) staticboolean mouseMoved(Object obj) staticboolean mousePressed(Object obj) staticvoid playSound(StringsoundFile) staticvoid setSpeed(intspeed) staticvoid start() staticvoid stop() Constructor. Delay execution by a number of time steps. The size of one time step is dened by the speed slider. Get the most recently pressed key since the last time this method was called. Return an object with information about the mouse state. Return a random number between 0 (inclusive) and limit (exclusive). Check whether a given key is currently pressed down. True if the mouse has been clicked on the given object. True if a mouse drag has ended. True if the mouse has been dragged on the given object. True if the mouse has been moved on the given object. True the mouse has been pressed on the given object. Play sound from a le. Set the speed of the simulation execution. Run (or resume) the simulation. Stop the simulation.

Class MouseInfo
Actor getActor() int getButton() int getClickCount() int getX() int getY() String toString() Return the actor (if any) that the current mouse behaviour is related to. The number of the pressed or clicked button (if any). The number of mouse clicks of this mouse event. The current x position of the mouse cursor. The current y position of the mouse cursor. Return a string representation of this mouse event info.

Class GreenfootSound
GreenfootSound(Stringfilename) boolean isPlaying() void pause() void play() void playLoop() void stop() String toString() Create a new sound from the given le. True if the sound is currently playing. Pauses the current sound if it is currently playing. Start playing this sound. Play this sound repeatedly in a loop. Stop playing this sound if it is currently playing. Returns a string representation of this sound containing the name of the le and whether it is currently playing or not.

Das könnte Ihnen auch gefallen