Genuts ME API

com.genuts.gameui
Class SpriteCounter

java.lang.Object
  extended bycom.genuts.gameui.Sprite
      extended bycom.genuts.gameui.SpriteLabel
          extended bycom.genuts.gameui.SpriteCounter
Direct Known Subclasses:
SpriteImageCounter

public class SpriteCounter
extends SpriteLabel

This object is for representation of all counter types such player's score.

It inherits from SpriteLabel to be able to inserted in a PlayField. By default, the counter is a background sprite.

To represent digits, the counter use the default font of the playfield.

You can specify the number of digit to display. By default, it is 3, and it will resize the component automaticly.
You have the ability to display all digits of the counter, or not to display 0 value on the left side. By default, the counter desn't display all digits.


Constructor Summary
SpriteCounter()
          Initializes the counter.
SpriteCounter(int digitsCount)
          Initializes the counter with a specified number of digits to display.
 
Method Summary
 void addValue(int value)
          Adds a value to the value of this counter.
 int getDigitsCount()
          Gets the number of digits to display.
 int getMaximumValue()
          Gets the maximum value of this counter.
 int getValue()
          Gets the value of this counter.
protected  void initSprite()
          Initializes the counter sprite.
 boolean isDisplayAllDigits()
          Indicates if all digits are displayed.
 void setDigitsCount(int digitsCount)
          Sets the number of digits to display.
 void setDisplayAllDigits(boolean display)
          Are all digits displayed?
 void setMaximumValue(int maxValue)
          Sets the maximum value for this counter.
 void setValue(int value)
          Sets the value of this counter.
 void subValue(int value)
          Subs a value to the value of this counter.
 
Methods inherited from class com.genuts.gameui.SpriteLabel
getBaseline, getColor, getFont, getText, paint, setBaseline, setColor, setFont, setParent, setText
 
Methods inherited from class com.genuts.gameui.Sprite
checkCollision, collisionWith, getActionSprite, getBackground, getBottomCollisionOffset, getFinalActionSprite, getFinalWrapper, getHeight, getId, getImage, getLeftCollisionOffset, getParent, getRightCollisionOffset, getTopCollisionOffset, getWidth, getWrapper, getX, getY, invalidate, isBackgroundSprite, isPremode, isSpriteAt, isValidate, isVisible, preCollisionWith, repaint, setBackground, setBackgroundSprite, setBottomCollisionOffset, setBounds, setId, setImage, setLeftCollisionOffset, setPosition, setPremode, setRightCollisionOffset, setSize, setTopCollisionOffset, setVisible, setWrapper, toString, validate
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Constructor Detail

SpriteCounter

public SpriteCounter()
Initializes the counter.


SpriteCounter

public SpriteCounter(int digitsCount)
Initializes the counter with a specified number of digits to display.

Parameters:
digitsCount - Number of digits to display.
Method Detail

setDigitsCount

public void setDigitsCount(int digitsCount)
Sets the number of digits to display.
This value must be greater or equal to 1.

Initializes the maximum value of this counter with yhe right value of digits.

Parameters:
digitsCount - Number of digits to display
Throws:
java.lang.IllegalAccessError - if the numberdigits to display is lower than 1.

getDigitsCount

public int getDigitsCount()
Gets the number of digits to display.

Returns:
The number of digit to display.

setMaximumValue

public void setMaximumValue(int maxValue)
Sets the maximum value for this counter.

Parameters:
maxValue - The maximum value for this counter.

getMaximumValue

public int getMaximumValue()
Gets the maximum value of this counter.

Returns:
The maximum value of this counter.

initSprite

protected void initSprite()
Initializes the counter sprite.

Overrides:
initSprite in class SpriteLabel

setValue

public void setValue(int value)
Sets the value of this counter.

If the value is greater than the max value, value is equal to value modulus maxValue.

Parameters:
value - Value to set.

getValue

public int getValue()
Gets the value of this counter.

Returns:
The value of this counter.

addValue

public void addValue(int value)
Adds a value to the value of this counter.

Parameters:
value - Value to add.

subValue

public void subValue(int value)
Subs a value to the value of this counter.

Parameters:
value - Value to sub.

setDisplayAllDigits

public void setDisplayAllDigits(boolean display)
Are all digits displayed?
All not used digits on the left side of the counter are displayed as 0 value.

Parameters:
display - true to display not used digits, false otherwise.

isDisplayAllDigits

public boolean isDisplayAllDigits()
Indicates if all digits are displayed.
All not used digits on the left side of the counter are displayed as 0 value.

Returns:
true to display not used digits, false otherwise.

Genuts ME API

Genuts ME API