|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectgreenfoot.sofiainternal.World
sofia.micro.World
sofia.micro.ScriptableWorld
public class ScriptableWorld
Represents a World that is controlled by a script--that is, a
predefined sequence of behavior played out over time. There are
two ways to provide a script: either override the script()
method in a subclass (most common for beginner programmers), or create a
script as a separate object and pass it into setScript(Script)
(more advanced, and more useful if there may be multiple scripts that
might be associated with a given world).
Constructor Summary | |
---|---|
ScriptableWorld()
Construct a new world with a default size of 20 x 12. |
|
ScriptableWorld(int width,
int height)
Construct a new world. |
|
ScriptableWorld(int width,
int height,
int scaledCellSize)
Construct a new world. |
Method Summary | |
---|---|
void |
act()
This implementation of the act method executes one action in this world's script. |
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. |
Script |
getScript()
Get the script associated with this actor. |
void |
remove(Actor actor)
Remove an Actor from the world. |
void |
script()
Subclasses can override this method to provide the "script" for the actor to follow. |
protected void |
scriptStep()
Triggers one action in this actor's script. |
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 |
setGridColor(sofia.graphics.Color gridColor)
Ask the world to draw visible grid lines of a specified color. |
void |
setScript(Script script)
Associate a script with this world by providing a Script
object. |
void |
setWorldBackground(Image background)
Set a background image to use for the entire world. |
void |
stopScript()
Stop any currently executing script associated with this actor. |
Methods inherited from class sofia.micro.World |
---|
backgroundIsForCells, getBackground, getHeight, getObjects, getObjects, getObjectsAt, getOrientation, getSpeed, getWidth, numberOfObjects, setActOrder, setCellBackground, setOrientation, setPaintOrder, setScaledCellSize, setSpeed, 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 |
---|
public ScriptableWorld()
If an image based on the world's class name exists, it will be used as the background for each cell.
public ScriptableWorld(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 ScriptableWorld(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 void add(Actor actor)
add
in class World
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.
add
in class World
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)
World
remove
in class World
actor
- The Actor to remove.public void act()
World
as your base
class.
If, on the other hand, you want to combine the features of
a scriptable world with a custom act() method, you can do that by
inheriting from this class and overriding this method. If you
override this method, be sure to call super.act()
or
your world will no longer obey its assigned script.
act
in class World
public void setGridColor(sofia.graphics.Color gridColor)
setGridColor
in class World
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)
setBackgroundColor
in class World
backgroundColor
- The color to use for the background of the world.public void setCellBackground(Image background)
setCellBackground
in class World
background
- The background image to use for each cell.public void setWorldBackground(Image background)
setWorldBackground
in class World
background
- The background image to use for the entire world.public void script()
script
in interface Script
public void setScript(Script script)
Script
object. Actions in the script will execute one move at a time as
act() is called. A script value of null will remove any assigned
script for this world.
script
- The script to activate.public Script getScript()
public void stopScript()
protected void scriptStep()
|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |