org.jrabbit.standard.game.objects.specialized
Class TextSprite

java.lang.Object
  extended by org.jrabbit.standard.game.objects.base.Spatial
      extended by org.jrabbit.standard.game.objects.base.BaseSprite
          extended by org.jrabbit.standard.game.objects.specialized.TextSprite
All Implemented Interfaces:
Renderable, Skin, GLTransform, Colored, Dimensioned, GLGroupTransformed, Located, Rotated, Scaled, ScreenObject, Visible

public class TextSprite
extends BaseSprite

A TextSprite is the basic Sprite used to render Text; it extends BaseSprite by using a TextSkin to render itself and manage its dimensions. The text and Font used by a TextSprite are both fully dynamic; to alter them, simply access the TextSkin and make the changes directly to it.

Author:
Chris Molini

Field Summary
protected  TextSkin textSkin
          The active TextSkin.
 
Fields inherited from class org.jrabbit.standard.game.objects.base.BaseSprite
color, screenCoords, transforms, visible
 
Fields inherited from class org.jrabbit.standard.game.objects.base.Spatial
location, rotation, scalar
 
Constructor Summary
TextSprite(java.lang.String text)
          Creates a TextSprite that uses the default Font to render the indicated text.
TextSprite(java.lang.String text, java.lang.String font)
          Creates a TextSprite that uses the indicated Font to render the indicated text.
TextSprite(TextSkin textSkin)
          Creates a TextSprite from the indicated TextSkin.
 
Method Summary
 void draw()
          Renders the active TextSkin.
 float height()
          Accesses the dimensions of the TextSkin.
 void setTextSkin(TextSkin textSkin)
          Redefines the TextSkin being used.
 TextSkin textSkin()
          Accesses the current TextSkin.
 float width()
          Accesses the dimensions of the TextSkin.
 
Methods inherited from class org.jrabbit.standard.game.objects.base.BaseSprite
bind, color, onscreen, release, render, screenCoords, setVisible, shouldRender, transforms, visible
 
Methods inherited from class org.jrabbit.standard.game.objects.base.Spatial
location, rotation, scalar, scaledDiameter, scaledHeight, scaledWidth
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

textSkin

protected TextSkin textSkin
The active TextSkin.

Constructor Detail

TextSprite

public TextSprite(java.lang.String text)
Creates a TextSprite that uses the default Font to render the indicated text.

Parameters:
text - The text to render.

TextSprite

public TextSprite(java.lang.String text,
                  java.lang.String font)
Creates a TextSprite that uses the indicated Font to render the indicated text.

Parameters:
text - The text to render.
font - The reference that identifies the Font to use.

TextSprite

public TextSprite(TextSkin textSkin)
Creates a TextSprite from the indicated TextSkin. NOTE: If you wish to use a RenderedTextSkin, simply supply one to this constructor.

Parameters:
textSkin - The TextSkin to use for rendering and dimension checking.
Method Detail

textSkin

public TextSkin textSkin()
Accesses the current TextSkin.

Returns:
The TextSkin being used.

setTextSkin

public void setTextSkin(TextSkin textSkin)
Redefines the TextSkin being used.

Parameters:
textSkin - The new TextSkin to use.

width

public float width()
Accesses the dimensions of the TextSkin. NOTE: Since Skins are supposed to be rendered from their center, but TextSkins are rendered from their top-left corners, there is a disparity between the value returned by this method and the width of the block of text being rendered. If the desired value is the width of the text itself, access the current TextSkin and call TextSkin.textWidth().

Returns:
The width of the active TextSkin.

height

public float height()
Accesses the dimensions of the TextSkin. NOTE: Since Skins are supposed to be rendered from their center, but TextSkins are rendered from their top-left corners, there is a disparity between the value returned by this method and the height of the block of text being rendered. If the desired value is the width of the text itself, access the current TextSkin and call TextSkin.textHeight().

Returns:
The height of the active TextSkin.

draw

public void draw()
Renders the active TextSkin.

Specified by:
draw in class BaseSprite