java.lang.Objectgreenfoot.Actor
Counter
public class Counter
A Counter class that allows you to display a numerical value on screen. The Counter is an actor, so you will need to create it, and then add it to the world in Greenfoot. If you keep a reference to the Counter then you can adjust its value. Here's an example of a world class that displays a counter with the number of act cycles that have occurred:
class CountingWorld
{
private Counter actCounter;
public CountingWorld()
{
super(600, 400, 1);
actCounter = new Counter("Act Cycles: ");
addObject(actCounter, 100, 100);
}
public void act()
{
actCounter.setValue(actCounter.getValue() + 1);
}
}
| Constructor Summary | |
|---|---|
Counter()
|
|
Counter(java.lang.String prefix)
Create a new counter, initialised to 0. |
|
| Method Summary | |
|---|---|
void |
act()
Animate the display to count up (or down) to the current target value. |
void |
add(int score)
Add a new score to the current counter value. |
int |
getValue()
Return the current counter value. |
void |
setPrefix(java.lang.String prefix)
Sets a text prefix that should be displayed before the counter value (e.g. |
void |
setValue(int newValue)
Set a new counter value. |
| Methods inherited from class greenfoot.Actor |
|---|
addedToWorld, getImage, getIntersectingObjects, getNeighbours, getObjectsAtOffset, getObjectsInRange, getOneIntersectingObject, getOneObjectAtOffset, getRotation, getWorld, getWorldOfType, getX, getY, intersects, isAtEdge, isTouching, move, removeTouching, setImage, setImage, setLocation, setRotation, turn, turnTowards |
| Methods inherited from class java.lang.Object |
|---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
| Constructor Detail |
|---|
public Counter()
public Counter(java.lang.String prefix)
| Method Detail |
|---|
public void act()
act in class greenfoot.Actorpublic void add(int score)
public int getValue()
public void setValue(int newValue)
public void setPrefix(java.lang.String prefix)