Vous êtes sur la page 1sur 4

Greenfoot API (v 2.4, for Greenfoot version 2.2.

0 or newer)
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 Actor
Actor() void act() protected void addedToWorld(World!world) GreenfootImage getImage() protected List getIntersectingObjects(Class!cls) protected List getNeighbours(int!distance, boolean!diagonal, Class!cls) 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.

protected!List getObjectsAtOffset(int!dx, Return all objects that intersect the given location (relative int!dy, Class!cls) to this object's location). protected List getObjectsInRange(int!r, Class!cls) protected!Actor getOneIntersectingObject(Class!cls) protected!Actor getOneObjectAtOffset(int!dx, int!dy, Class!cls) 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.

protected!boolean intersects(Actor!other) Check whether this object intersects another given object. void move(int distance) void setImage(GreenfootImage!image) void setImage(String!filename) void setLocation(int!x, int!y) void setRotation(int!rotation) void turn(int amount) void turnTowards(int x, int y) Move this actor the specied distance in the direction it is currently facing. 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. Turn this actor by the specied amount (in degrees). Turn this actor to face towards a given location.

Class World
World(int!worldWidth, int!worldHeight, int!cellSize) World(int!worldWidth, int!worldHeight, int!cellSize, boolean bounded) void act() void addObject(Actor!object, int!x, int!y) GreenfootImage getBackground() int getCellSize() Color getColorAt(int!x, int!y) int getHeight() List getObjects(Class!cls) List getObjectsAt(int!x, int!y, Class!cls) int getWidth() int numberOfObjects() void removeObject(Actor!object) void removeObjects(Collection!objects) void repaint() void setActOrder(Class... classes) void setBackground(GreenfootImage!image) void setBackground(String!filename) void setPaintOrder(Class... classes) void started() void stopped() Construct a new world. Construct a new world with the option to create an unbounded world where actors can leave the 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.

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 Greenfoot
Greenfoot() static!void delay(int time) static!String getKey() static!String getMicLevel() static MouseInfo getMouseInfo() static!int getRandomNumber(int!limit) static!boolean isKeyDown(String!keyName) static!boolean mouseClicked(Object obj) static!boolean mouseDragEnded(Object obj) static!boolean mouseDragged(Object obj) static!boolean mouseMoved(Object obj) static!boolean mousePressed(Object obj) static!void playSound(String!soundFile) static!void setSpeed(int!speed) static!void setWorld(int!speed) static!void start() static!void 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. Get the microphone input level. 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. Sets the World to run to the one given. Run (or resume) the simulation. Stop the simulation.

Class GreenfootImage
GreenfootImage(GreenfootImage!image) GreenfootImage(int!width, int!height) GreenfootImage(String!filename) GreenfootImage(String!string, int!size, Color!foreground, Color!background) void clear() void drawImage(GreenfootImage!image, int!x, int!y) void drawLine(int!x1, int!y1, int!x2, int!y2) void drawOval(int!x, int!y, int!width, int!height) void drawPolygon(int[]!xPoints, int[]!yPoints, int!nPoints) void drawRect(int!x, int!y, int!width, int!height) void drawShape(Shape shape) 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. 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 a shape directly on the image. (continued next page)

Class GreenfootImage
void drawString(String!string, int!x, int!y) void fill() void fillOval(int!x, int!y, int!width, int!height) void fillPolygon(int[]!xPoints, int[]!yPoints, int!nPoints) void fillRect(int!x, int!y, int!width, int!height) void fillShape(Shape shape) BufferedImage getAwtImage() Color getColor() Color getColorAt(int!x, int!y) Font getFont() int getHeight() int getTransparency() int getWidth() void mirrorHorizontally() void mirrorVertically() void rotate(int!degrees) void scale(int!width, int!height) void setColor(Color!color) 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. Draw a lled shape directly on the image. 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(int!x, int!y, Color!color) Sets the color at the given pixel to the given color. void setFont(Font!f) 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.

Class GreenfootSound
GreenfootSound(String!filename) int getVolume() boolean isPlaying() void pause() void play() void playLoop() void setVolume(int level) void stop() String toString() Create a new sound from the given le. Get the current volume of the sound, between 0 (off) and 100 (loudest). 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. Set the current volume of the sound between 0 (off) and 100 (loudest). 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.

Vous aimerez peut-être aussi