Class Counter
- java.lang.Object
-
- greenfoot.Actor
-
- Counter
-
public class Counter extends greenfoot.ActorA 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); } }- Version:
- 1.0
- Author:
- Neil Brown and Michael Kölling
-
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description voidact()Animate the display to count up (or down) to the current target value.voidadd(int score)Add a new score to the current counter value.intgetValue()Return the current counter value.voidsetPrefix(java.lang.String prefix)Sets a text prefix that should be displayed before the counter value (e.g.voidsetValue(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
-
-
-
-
Method Detail
-
act
public void act()
Animate the display to count up (or down) to the current target value.- Overrides:
actin classgreenfoot.Actor
-
add
public void add(int score)
Add a new score to the current counter value. This will animate the counter over consecutive frames until it reaches the new value.
-
getValue
public int getValue()
Return the current counter value.
-
setValue
public void setValue(int newValue)
Set a new counter value. This will not animate the counter.
-
setPrefix
public void setPrefix(java.lang.String prefix)
Sets a text prefix that should be displayed before the counter value (e.g. "Score: ").
-
-