GF4J 0.9.4 Beta

gameframe.util
Class Counter

java.lang.Object
  |
  +--gameframe.util.Counter

public class Counter
extends java.lang.Object

A counter that can display almost any number of digits. The counter uses a rolling counter by default. In order to update the shown value you must tick() this counter. This causes the counter to adjust its value towards the final value in steps (makes a nice rolling effect). Methods addImmediately and decImmediately adjust the counter immediately. The maximum number of digits this counter can show is the maximum number of digits that can fit to an integer.

Since:
GameFrame for Java 0.9.4
Version:
GameFrame for Java 0.9.4

Field Summary
private  int[] m_aCounts
          Count for each of the 10 exp n values (n starts from 0 ).
private  DrawableBitmap[] m_aNumbers
          The images that represent numbers.
private  int[] m_aX
          The x coordinate for the count at index n.
private  int m_currentCount
          The currently displayed value of this counter.
private  int m_destCount
          The real value of this counter that it is rolling towards.
private  int m_fontHeight
          The height of one font image.
private  int m_fontWidth
          The width of one font image.
private  int m_initialCount
          The initial count value, used when the counter is reset.
private  long m_lastTime
          The last time player was ticked.
private  int m_numDigits
          The number of digits (between 1 to 6) that are displayed.
private  int m_x
          Base x-coordinate of the counter.
private  int m_y
          Base y-coordinate of the counter.
 
Constructor Summary
Counter(int initialCount, int x, int y, int numDigits)
          Constructs a counter that uses the currently set font bitmap for numbers, has the given initial value, is located at the given screen coordinates and uses the given number of digits.
 
Method Summary
 void add(int count)
          Adds the given number to the counter.
 void addImmediately(int count)
          Adds the given number to the counter immediately.
 void dec(int count)
          Decrements the given number from the counter.
 void decImmediately(int count)
          Decrements the given number from the counter immediately.
 int getCount()
          Returns the current (real) counter value.
 int getHeight()
          Returns the height of this counter.
 int getWidth()
          Returns the width of this counter.
 int getX()
          Returns the base x-coordinate of the counter based upon the number of digits it needs to display.
 int getY()
          Returns the base y-coordinate.
 void paint()
          Paints this counter to the backbuffer.
 void reset()
          Resets this counter to its inital value.
 void setCount(int count)
          Sets the count of this counter to the given number.
 void setImmediately(int count)
          Sets the given counter value immediately without the fancy scrolling effect.
 void setX(int x)
          Sets the upper left coordinate.
 void setY(int y)
          Sets the upper left coordinate.
 void tick()
          Calcultes the value of this counter every time called.
private  void updateCount()
          Updates the number display values from the actual counter value.
 
Methods inherited from class java.lang.Object
, clone, equals, finalize, getClass, hashCode, notify, notifyAll, registerNatives, toString, wait, wait, wait
 

Field Detail

m_destCount

private int m_destCount
The real value of this counter that it is rolling towards.

m_currentCount

private int m_currentCount
The currently displayed value of this counter.

m_initialCount

private int m_initialCount
The initial count value, used when the counter is reset.

m_aCounts

private int[] m_aCounts
Count for each of the 10 exp n values (n starts from 0 ).

m_aX

private int[] m_aX
The x coordinate for the count at index n.

m_x

private int m_x
Base x-coordinate of the counter.

m_y

private int m_y
Base y-coordinate of the counter.

m_fontWidth

private int m_fontWidth
The width of one font image.

m_fontHeight

private int m_fontHeight
The height of one font image.

m_aNumbers

private DrawableBitmap[] m_aNumbers
The images that represent numbers.

m_lastTime

private long m_lastTime
The last time player was ticked.

m_numDigits

private int m_numDigits
The number of digits (between 1 to 6) that are displayed.
Constructor Detail

Counter

public Counter(int initialCount,
               int x,
               int y,
               int numDigits)
        throws GameFrameException
Constructs a counter that uses the currently set font bitmap for numbers, has the given initial value, is located at the given screen coordinates and uses the given number of digits.
Parameters:
aNumbers - The bitmaps that represent numbers.
initialCount - The initial counter value.
x - The base x-coordinate of the counter.
y - The base y-coordinate of the counter.
numDigits - The number of digits (between 1 to 6) that are displayed.
Method Detail

tick

public void tick()
Calcultes the value of this counter every time called.

reset

public void reset()
Resets this counter to its inital value.

paint

public void paint()
Paints this counter to the backbuffer.

getCount

public int getCount()
Returns the current (real) counter value.
Returns:
The current counter value.

add

public void add(int count)
Adds the given number to the counter.
Parameters:
count - The number to add to this counter.

addImmediately

public void addImmediately(int count)
Adds the given number to the counter immediately.
Parameters:
count - The number to add to this counter.

dec

public void dec(int count)
Decrements the given number from the counter.
Parameters:
count - The number to decrement from this counter.

decImmediately

public void decImmediately(int count)
Decrements the given number from the counter immediately.
Parameters:
count - The number to decrement from this counter.

setCount

public void setCount(int count)
Sets the count of this counter to the given number.
Parameters:
count - The counters new value.

setImmediately

public void setImmediately(int count)
Sets the given counter value immediately without the fancy scrolling effect.

updateCount

private final void updateCount()
Updates the number display values from the actual counter value.

getX

public int getX()
Returns the base x-coordinate of the counter based upon the number of digits it needs to display. The base coordinate is the leftmost numbers coordinate.
Returns:
The base x-coordinate.

setX

public void setX(int x)
Sets the upper left coordinate.
Parameters:
x - The x-coordinate this counter will use.

getY

public int getY()
Returns the base y-coordinate. The base coordinate is the topmost y-coordinate of the counter.
Returns:
Base y-coordinate.

setY

public void setY(int y)
Sets the upper left coordinate.
Parameters:
y - The y-coordinate this counter will use.

getWidth

public int getWidth()
Returns the width of this counter.
Returns:
Width of this counter.

getHeight

public int getHeight()
Returns the height of this counter.
Returns:
Height of this counter.

GF4J 0.9.4 Beta