sofia.micro.greenfoot
Class World

java.lang.Object
  extended by greenfoot.sofiainternal.World
      extended by sofia.micro.World
          extended by sofia.micro.greenfoot.World

public class World
extends World

A small "adaptor" class that provides Greenfoot-style methods for some World features. It is intended to provide for source-level compatibility of some Greenfoot examples.

Version:
$Date: 2012/08/06 11:13 $
Author:
Stephen Edwards, Last changed by $Author: edwards $

Constructor Summary
World()
          Construct a new world with a default size of 20 x 12.
World(int width, int height)
          Construct a new world.
World(int width, int height, int scaledCellSize)
          Construct a new world.
 
Method Summary
 void addObject(Actor actor, int x, int y)
          Add an Actor to the world at a specified location.
 void removeObject(Actor actor)
          Remove an Actor from the world.
 void setBackground(Image background)
          Set a background image to use for each Cell.
 void setBackground(java.lang.String background)
          Set a background image to use for each Cell.
 
Methods inherited from class sofia.micro.World
act, add, add, backgroundIsForCells, getBackground, getHeight, getObjects, getObjects, getObjectsAt, getOrientation, getSpeed, getWidth, numberOfObjects, remove, setActOrder, setBackgroundColor, setCellBackground, setCellBackground, setGridColor, setOrientation, setPaintOrder, setScaledCellSize, setSpeed, setWorldBackground, setWorldBackground, start, started, stop, stopped
 
Methods inherited from class greenfoot.sofiainternal.World
_gf_addObject, _gf_getBackground, _gf_getCellSize, _gf_getColorAt, _gf_getIntersectingObjects, _gf_getNeighbours, _gf_getObjects, _gf_getObjectsAt, _gf_getObjectsInDirection, _gf_getObjectsInRange, _gf_getOneIntersectingObject, _gf_getOneObjectAt, _gf_removeObject, _gf_removeObjects, _gf_repaint, _gf_setActOrder, _gf_setBackground, _gf_setBackground, _gf_setPaintOrder
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

World

public World()
Construct a new world with a default size of 20 x 12. This default size is based on a 320x480 (Android's HVGA resolution, which is a mid-level phone resolution) in landscape orientation, leaving some room for a notification bar and other decorations. This would result in 24x24 pixel cells, or 16x16 cells on a 240x320 phone. This world (and its actors) will be automatically scaled up (zoomed) if the Android device resolution permits it.

If an image based on the world's class name exists, it will be used as the background for each cell.


World

public World(int width,
             int height)
Construct a new world. The size of the world (in number of cells) must be specified. This world (and its actors) will be automatically scaled up (zoomed) if the Android device resolution permits it.

If an image based on the world's class name exists, it will be used as the background for each cell.

Parameters:
width - The width of the world (in cells).
height - The height of the world (in cells).

World

public World(int width,
             int height,
             int scaledCellSize)
Construct a new world. The size of the world (in number of cells) must be specified. This constructor also sets the effective cell size of this world (for bitmaps). This world (and its actors) will be automatically scaled up (zoomed) if the Android device resolution permits it.

If an image based on the world's class name exists, it will be used as the background for each cell.

Parameters:
width - The width of the world (in cells).
height - The height of the world (in cells).
scaledCellSize - For rendering bitmaps, treat each cell as if it were a square of this many pixels on each side.
Method Detail

addObject

public void addObject(Actor actor,
                      int x,
                      int y)
Add an Actor to the world at a specified location.

This method is identical to add(), but is provided for Greenfoot compatibility.

Parameters:
actor - The Actor to add.
x - The x coordinate of the location where the actor is added.
y - The y coordinate of the location where the actor is added.

removeObject

public void removeObject(Actor actor)
Remove an Actor from the world.

This method is identical to remove(), but is provided for Greenfoot compatibility.

Parameters:
actor - The Actor to remove.

setBackground

public void setBackground(Image background)
Set a background image to use for each Cell. The given image will be scaled to fill exactly one cell, and tiled across the entire world's grid. This will replace any world background image.

Parameters:
background - The background image to use for each cell.

setBackground

public void setBackground(java.lang.String background)
Set a background image to use for each Cell. The given image will be scaled to fill exactly one cell, and tiled across the entire world's grid. This will replace any world background image.

Parameters:
background - The background image to use for each cell.


Greenfoot homepage