public class Counter
extends greenfoot.Actor
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 and Description |
|---|
Counter() |
Counter(java.lang.String prefix)
Create a new counter, initialised to 0.
|
| Modifier and Type | Method and Description |
|---|---|
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.
|
addedToWorld, getImage, getIntersectingObjects, getNeighbours, getObjectsAtOffset, getObjectsInRange, getOneIntersectingObject, getOneObjectAtOffset, getRotation, getWorld, getWorldOfType, getX, getY, intersects, isAtEdge, isTouching, move, removeTouching, setImage, setImage, setLocation, setRotation, turn, turnTowardspublic Counter()
public Counter(java.lang.String prefix)
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)