java.lang.Objectgreenfoot.World
ThreadWorld
public abstract class ThreadWorld
class of Threadfoot
Counterpart of Greenfoot-class World. Working with Threadfoot you should use always this class instead of class World.
Remark 1: If you override the methods "started" or "stopped" in a derived class you have to call the ThreadWorld-methods "started" respectively "stopped" within those methods!
Remark 2: Do not use method "setBackground". Use "setImage" instead. (World.setBackground is declared final and could not be overridden.)
Constructor Summary | |
---|---|
ThreadWorld(int worldWidth,
int worldHeight,
int cellSize)
Construct a new world. |
|
ThreadWorld(int worldWidth,
int worldHeight,
int cellSize,
boolean bounded)
Construct a new world. |
Method Summary | |
---|---|
void |
act()
meaningless in Threadfoot |
void |
addObject(greenfoot.Actor object,
int x,
int y)
Add an Actor to the world. |
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 centre of the cell. |
int |
getHeight()
Return the height of the world (in number of cells). |
java.util.List |
getObjects(java.lang.Class cls)
Get all the objects in the world, or all the objects of a particular class. |
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). |
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)
Set the act order of objects in the world. |
void |
setImage(greenfoot.GreenfootImage image)
Set a background image for the world. |
void |
setImage(java.lang.String filename)
Set a background image for the world from an image file. |
void |
setPaintOrder(java.lang.Class... classes)
Set the paint order of objects in the world. |
void |
started()
This method is called by the Greenfoot system when the execution has started. |
void |
stopped()
This method is called by the Greenfoot system when the execution has stopped. |
Methods inherited from class greenfoot.World |
---|
setBackground, setBackground |
Methods inherited from class java.lang.Object |
---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Constructor Detail |
---|
public ThreadWorld(int worldWidth, int worldHeight, int cellSize)
worldWidth
- The width of the world (in cells).worldHeight
- The height of the world (in cells).cellSize
- Size of a cell in pixels.public ThreadWorld(int worldWidth, int worldHeight, int cellSize, boolean bounded)
worldWidth
- The width of the world (in cells).worldHeight
- The height of the world (in cells).cellSize
- Size of a cell in pixels.bounded
- Should actors be restricted to the world boundary?Method Detail |
---|
public final void act()
act
in class greenfoot.World
World.act()
public void addObject(greenfoot.Actor object, int x, int y)
addObject
in class greenfoot.World
object
- The new object to add.x
- The x coordinate of the location where the object is added.y
- The y coordinate of the location where the object is added.public greenfoot.GreenfootImage getBackground()
getBackground
in class greenfoot.World
public int getCellSize()
getCellSize
in class greenfoot.World
public java.awt.Color getColorAt(int x, int y)
getColorAt
in class greenfoot.World
x
- The x coordinate of the cell.y
- The y coordinate of the cell.
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.getBackground()
public int getHeight()
getHeight
in class greenfoot.World
public java.util.List getObjects(java.lang.Class cls)
If a class is specified as a parameter, only objects of that class (or its subclasses) will be returned.
getObjects
in class greenfoot.World
cls
- Class of objects to look for ('null' will find all objects).
public java.util.List getObjectsAt(int x, int y, java.lang.Class cls)
An object is defined to be at that cell if its graphical representation overlaps with the cell at any point.
getObjectsAt
in class greenfoot.World
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).public int getWidth()
getWidth
in class greenfoot.World
public int numberOfObjects()
numberOfObjects
in class greenfoot.World
public void removeObject(greenfoot.Actor object)
removeObject
in class greenfoot.World
object
- the object to removepublic void removeObjects(java.util.Collection objects)
removeObjects
in class greenfoot.World
objects
- A list of Actors to remove.public void repaint()
repaint
in class greenfoot.World
public void setActOrder(java.lang.Class... classes)
Objects of a class not explicitly specified inherit the act order from their superclass.
Objects of classes not listed will act after all objects whose classes have been specified.
setActOrder
in class greenfoot.World
classes
- The classes in desired act orderpublic void setImage(greenfoot.GreenfootImage image)
Do not use method "setBackground". Use "setImage" instead.
image
- The image to be shownWorld.setBackground(String)
public void setImage(java.lang.String filename) throws java.lang.IllegalArgumentException
Do not use method "setBackground". Use "setImage" instead.
filename
- The file holding the image to be shown
java.lang.IllegalArgumentException
- If the image can not be loaded.World.setBackground(GreenfootImage)
public void setPaintOrder(java.lang.Class... classes)
Objects of a class not explicitly specified effectively inherit the paint order from their superclass.
Objects of classes not listed will appear below the objects whose classes have been specified.
setPaintOrder
in class greenfoot.World
classes
- The classes in desired paint orderpublic void started()
If you override this method in a derived class you have to call this method within those methods!
started
in class greenfoot.World
World.started()
public void stopped()
If you override this method in a derived class you have to call this method within those methods!
stopped
in class greenfoot.World
World.stopped()