## greenfoot
Class World

    java.lang.Object
      greenfoot.World

    public abstract class World

extends java.lang.Object

World is the world that Actors live in. It is a two-dimensional grid of cells.
All Actor are associated with a World and can get access to the world object. The size of cells can be specified at world creation time, and is constant after creation. Simple scenarios may use large cells that entirely contain the representations of objects in a single cell. More elaborate scenarios may use smaller cells (down to single pixel size) to achieve fine-grained placement and smoother animation. The world background can be decorated with drawings or images.

Version:
  1.4.0
Author:
  Poul Henriksen, Michael Kolling
See Also:
  `Actor`

Constructor Summary
`World(int worldWidth, int worldHeight, int cellSize)` Construct a new world.

Method Summary
`void` | `act()` Act method for world.
`void` | `addObject(greenfoot.Actor object, int x, int y)` Add an Actor to the world (at the object's specified location).
`greenfoot.GreenfootImage` | `getBackground()` Return the world's background image.
`int` | `getCellSize()` Return the size of a cell (in pixels).
`java.awt.Color` | `getColorAt(int x, int y)` Return the color at the center of the cell.
`int` | `getHeight()` Return the height of the world (in number of cells).
`java.util.List` | `getObjectsAt(int x, int y, java.lang.Class cls)` Return all objects at a given cell.
`int` | `getWidth()` Return the width of the world (in number of cells).
`boolean` | `isTiled()` Returns true if the world is tiled.
`int` | `numberOfObjects()` Get the number of actors currently in the world.
`void` | `removeObject(greenfoot.Actor object)` Remove an object from the world.
`void` | `removeObjects(java.util.Collection objects)` Remove a list of objects from the world.
`void` | `repaint()` Repaints the world.
`void` | `setActOrder(java.lang.Class... classes)` Sets the act order of objects in the world according to their class.
`void` | `setBackground(greenfoot.GreenfootImage image)` Set a background image for the world.
`void` | `setBackground(java.lang.String filename)` Set a background image for the world from an image file.
`void` | `setPaintOrder(java.lang.Class... classes)` Sets the paint order of objects in the world according to their class.
`void` | `setTiled(boolean tiled)` If set to true, the background image will be tiled to fill out the entire background of the world.

Methods inherited from class java.lang.Object
`clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait`

Constructor Detail

### World

    public World(int worldWidth,
                 int worldHeight,
                 int cellSize)

  Construct a new world. The size of the world (in number of cells) and the size of each cell (in pixels) must be specified.

  Parameters:
    `worldWidth` - The width of the world (in cells).
    `worldHeight` - The height of the world (in cells).
    `cellSize` - Size of a cell in pixels.

Method Detail

### act

    public void act()

  Act method for world. The act method is called by the greenfoot framework at each action step in the environment. The world's act method is called before the act method of any objects in the world.

  This method does nothing. It should be overridden in subclasses to implement an world's action.

### addObject

    public void addObject(greenfoot.Actor object,
                          int x,
                          int y)
                   throws java.lang.IndexOutOfBoundsException

  Add an Actor to the world (at the object's specified location).

  Parameters:
    `object` - The new object to add.
  Throws:
    `java.lang.IndexOutOfBoundsException` - If the coordinates are outside the bounds of the world.

### getBackground

    public greenfoot.GreenfootImage getBackground()

  Return the world's background image. The image may be used to draw onto the world's background.

  Returns:
    The background image

### getCellSize

    public int getCellSize()

  Return the size of a cell (in pixels).

### getColorAt

    public java.awt.Color getColorAt(int x,
                                     int y)

  Return the color at the center of the cell. To paint a color, you need to get the background image for the world and paint on that.

  Throws:
    `java.lang.IndexOutOfBoundsException` - If the location is not within the world bounds. If there is no background image at the location it will return Color.WHITE.
  See Also:
    `getBackground()`

### getHeight

    public int getHeight()

  Return the height of the world (in number of cells).

### getObjectsAt

    public java.util.List getObjectsAt(int x,
                                       int y,
                                       java.lang.Class cls)

  Return all objects at a given cell.

  An object is defined to be at that cell if its graphical representation overlaps with the cell at any point.

  Parameters:
    `x` - X-coordinate of the cell to be checked.
    `y` - Y-coordinate of the cell to be checked.
    `cls` - Class of objects to look return ('null' will return all objects).

### getWidth

    public int getWidth()

  Return the width of the world (in number of cells).

### isTiled

    public boolean isTiled()

  Returns true if the world is tiled.

  Returns:
    Whether the image is tilled.
  See Also:
    `setTiled(boolean)`

### numberOfObjects

    public int numberOfObjects()

  Get the number of actors currently in the world.

  Returns:
    The number of actors

### removeObject

    public void removeObject(greenfoot.Actor object)

  Remove an object from the world.

  Parameters:
    `object` - the object to remove

### removeObjects

    public void removeObjects(java.util.Collection objects)

  Remove a list of objects from the world.

  Parameters:
    `objects` - A list of Actors to remove.

### repaint

    public void repaint()

  Repaints the world.

### setActOrder

    public void setActOrder(java.lang.Class... classes)

  Sets the act order of objects in the world according to their class. Objects of the first class given will act first; objects of the second class given will act second, and so on.

  Objects of a class not explicitly specified effectively inherit the act order from their superclass.

  Objects not belonging to any of the given classes will act after all other actors.

  Parameters:
    `classes` - The classes in desired act order

### setBackground

    public final void setBackground(greenfoot.GreenfootImage image)

  Set a background image for the world. If the image size is larger than the world in pixels, it is clipped. If it is smaller than the world, it is tiled unless specifically stated to do otherwise (see setTiled()). A pattern showing the cells can easily be shown by setting a background image with a size equal to the cell size.

  Parameters:
    `image` - The image to be shown
  See Also:
    `setBackground(String)`, `setTiled(boolean)`

### setBackground

    public final void setBackground(java.lang.String filename)
                             throws java.lang.IllegalArgumentException

  Set a background image for the world from an image file. Images of type 'jpeg', 'gif' and 'png' are supported. If the image size is larger than the world in pixels, it is clipped. If it is smaller than the world, it is tiled unless specifically stated to do otherwise (see setTiled()). A pattern showing the cells can easily be shown by setting a background image with a size equal to the cell size.

  Parameters:
    `filename` - The file holding the image to be shown
  Throws:
    `java.lang.IllegalArgumentException` - If the image can not be loaded.
  See Also:
    `setBackground(GreenfootImage)`, `setTiled(boolean)`

### setPaintOrder

    public void setPaintOrder(java.lang.Class... classes)

  Sets the paint order of objects in the world according to their class. Objects of the first class given will be painted last, so they will appear on top of all other objects; objects of the second class given will be painted second last, and so on.

  Objects of a class not explicitly specified effectively inherit the paint order from their superclass.

  Objects not belonging to any of the given classes will appear underneath all other objects.

  Parameters:
    `classes` - The classes in desired paint order

### setTiled

    public void setTiled(boolean tiled)

  If set to true, the background image will be tiled to fill out the entire background of the world.

  Parameters:
    `tiled` - Whether it should tile the image or not.