|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectgreenfoot.sofiainternal.World
sofia.micro.World
public class World
Represents a "microworld" containing Actors and rendered on a screen.
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 |
act()
Act method for world. |
|
void |
add(Actor actor)
Add an Actor to the world. |
|
void |
add(Actor actor,
int x,
int y)
Add an Actor to the world at a specified location. |
|
boolean |
backgroundIsForCells()
Return whether the background image is scaled to each cell and repeated, or stretched over the entire grid. |
|
Image |
getBackground()
Return the world's background image. |
|
int |
getHeight()
Return the height of the world (in number of cells). |
|
java.util.Set<Actor> |
getObjects()
Get all the actors in the world. |
|
|
getObjects(java.lang.Class<MyActor> cls)
Get all the actors of the specified type in this world. |
|
|
getObjectsAt(float x,
float y,
java.lang.Class<MyActor> cls)
Return all objects of the specified type at a given cell. |
|
int |
getOrientation()
Get the preferred orientation of this world. |
|
int |
getSpeed()
Get the speed of this world, which determines the delay between successive steps where act() is called on all Actors. |
|
int |
getWidth()
Return the width of the world (in number of cells). |
|
int |
numberOfObjects()
Get the number of actors currently in the world. |
|
void |
remove(Actor actor)
Remove an Actor from the world. |
|
void |
setActOrder(java.lang.Class<? extends Actor>... classes)
Set the act order of objects in the world. |
|
void |
setBackgroundColor(sofia.graphics.Color backgroundColor)
Set the color of the world's background, if you prefer a solid color background instead of an Image. |
|
void |
setCellBackground(Image background)
Set a background image to use for each Cell. |
|
void |
setCellBackground(java.lang.String background)
Set a background image to use for each Cell. |
|
void |
setGridColor(sofia.graphics.Color gridColor)
Ask the world to draw visible grid lines of a specified color. |
|
void |
setOrientation(int orientation)
Determine the preferred orientation of this World when displayed on the device. |
|
void |
setPaintOrder(java.lang.Class<? extends Actor>... classes)
Set the paint order of objects in the world. |
|
void |
setScaledCellSize(int scaledCellSize,
boolean scaleToFit)
Set the effective cell size of this world (for bitmaps) and whether this world (and its actors) should be automatically scaled up (zoomed) if the Android device resolution permits it. |
|
void |
setSpeed(int speed)
Set the speed of this world, which determines the delay between successive steps where act() is called on all Actors. |
|
void |
setWorldBackground(Image background)
Set a background image to use for the entire world. |
|
void |
setWorldBackground(java.lang.String background)
Set a background image to use for the entire world. |
|
void |
start()
Start (or run, or resume) the world. |
|
void |
started()
This method is called by the system when the execution has started. |
|
void |
stop()
Stop (or pause running of) the world. |
|
void |
stopped()
This method is called by the system when the execution has 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 |
---|
public World()
If an image based on the world's class name exists, it will be used as the background for each cell.
public World(int width, int height)
If an image based on the world's class name exists, it will be used as the background for each cell.
width
- The width of the world (in cells).height
- The height of the world (in cells).public World(int width, int height, int scaledCellSize)
If an image based on the world's class name exists, it will be used as the background for each cell.
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 |
---|
public int getWidth()
getWidth
in class greenfoot.sofiainternal.World
public int getHeight()
getHeight
in class greenfoot.sofiainternal.World
public void add(Actor actor)
actor
- The Actor to add.public void add(Actor actor, int x, int y)
add()
on
an actor, and then calling setGridLocation()
on the actor
to specify its position.
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.public void remove(Actor actor)
actor
- The Actor to remove.public void setGridColor(sofia.graphics.Color gridColor)
gridColor
- The color to use for grid lines around each cell,
or null to suppress grid lines (the default).public void setBackgroundColor(sofia.graphics.Color backgroundColor)
backgroundColor
- The color to use for the background of the world.public void setCellBackground(java.lang.String background)
background
- The background image to use for each cell.public void setCellBackground(Image background)
background
- The background image to use for each cell.public void setWorldBackground(java.lang.String background)
background
- The background image to use for the entire world.public void setWorldBackground(Image background)
background
- The background image to use for the entire world.public Image getBackground()
public boolean backgroundIsForCells()
public void setPaintOrder(java.lang.Class<? extends Actor>... classes)
Objects of classes listed first in the parameter list will appear on top of all objects of classes listed later.
Objects of a class not explicitly specified inherit the paint order from their superclass.
Objects of classes not listed will appear below the objects whose classes have been specified.
classes
- The classes in desired paint order.public void setActOrder(java.lang.Class<? extends Actor>... classes)
Objects of classes listed first in the parameter list will act before any objects of classes listed later.
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.
classes
- The classes in desired act order.public java.util.Set<Actor> getObjects()
public <MyActor extends Actor> java.util.Set<MyActor> getObjects(java.lang.Class<MyActor> cls)
MyActor
- The type of actor to look for, as specified
in the cls parameter.cls
- Class of objects to look for (passing 'null' will find all
objects).
public int numberOfObjects()
numberOfObjects
in class greenfoot.sofiainternal.World
public void act()
This method does nothing. It should be overridden in subclasses to implement an world's action.
act
in class greenfoot.sofiainternal.World
public void started()
This default implementation is empty.
started
in class greenfoot.sofiainternal.World
public void stopped()
This default implementation is empty.
stopped
in class greenfoot.sofiainternal.World
public <MyActor extends Actor> java.util.Set<MyActor> getObjectsAt(float x, float y, java.lang.Class<MyActor> cls)
An object is defined to be at that cell if its graphical representation overlaps the center of the cell.
MyActor
- The type of actor to look for, as specified
in the cls parameter.x
- X-coordinate of the cell to be checked.y
- Y-coordinate of the cell to be checked.cls
- Class of objects to find ('null' will return all
objects).
public void setOrientation(int orientation)
orientation
- The orientation to use, specified as one of
the screen orientation constants defined in
android.content.pm.ActivityInfo
; typically,
either
android.content.pm.ActivityInfo#SCREEN_ORIENTATION_LANDSCAPE
(locks the display in landscape orientation),
android.content.pm.ActivityInfo#SCREEN_ORIENTATION_PORTRAIT
(locks the display in portrait orientation),
or
android.content.pm.ActivityInfo#SCREEN_ORIENTATION_SENSOR
(the orientation is controlled by the device's built-in
orientation sensor).public int getOrientation()
setOrientation(int)
public void setScaledCellSize(int scaledCellSize, boolean scaleToFit)
scaledCellSize
- For rendering bitmaps, treat each cell as if
it were a square of this many pixels on each side.scaleToFit
- If true, cells will be scaled larger or smaller
so that the grid is as large as possible on
the physical device, with bitmaps
scaled proportionately. If false, the grid
will be rendered so that each cell is exactly
scaledCellSize pixels in size, no more and no
less, even if this means some of the grid will
be clipped by the screen boundaries.public void setSpeed(int speed)
speed
- The new speed (0-100)public int getSpeed()
public void start()
public void stop()
|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |