Artenus 2D Framework
Artenus Reference
Represents a text block. A text is a series of characters displayed on the screen using a Font. This class provides all controls relating to size, color and text manipulation to manage the piece of text that is added to the scene.

See Also:

public final class TextSprite
extends SpriteEntity

Field Summary

Fields inherited from com.annahid.libs.artenus.graphics.sprites.SpriteEntity

Constructor Summary

Modifier and TypeConstructor and Description
public TextSprite(Font font, int fontSize)
Creates a TextSprite using the given font and font size.
public TextSprite(Font font, int fontSize, String initialText)
Creates a TextSprite using the given font and font size.

Method Summary

Modifier and TypeMethod and Description
public voidcenterAt(Point2D p)
Sets the position of the text sprite so that it is centered at the given point.
public voidcenterAt(float x, float y)
Sets the position of the text sprite so that it is centered at the given point.
public final FontgetFont()
Gets the current font assigned to this TextSprite.
public final StringgetText()
Gets the string representation of the text currently displayed for this TextSprite.
public final booleanisTextEmpty()
Determines whether this TextSprite represents an empty text.
public final voidrender(RenderingContext ctx, int flags)
Renders the visual content.
public final voidsetFont(Font font)
Assigns a new font to this TextSprite.
public voidsetRTL(boolean isRtl)
Sets the right-to-left state of this TextSprite.
public final voidsetText(String value)
Sets the text on this TextSprite.

Methods inherited from com.annahid.libs.artenus.graphics.sprites.SpriteEntity

Methods inherited from java.lang.Object

clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait

Constructor Detail

TextSprite
public  TextSprite(
    Font font,
    int fontSize
)
Creates a TextSprite using the given font and font size.
Parameters:
fontThe font for this text
fontSizeThe font size to use
TextSprite
public  TextSprite(
    Font font,
    int fontSize,
    String initialText
)
Creates a TextSprite using the given font and font size. The text initially displayed for the sprite is also specified.
Parameters:
fontThe font for this text
fontSizeThe font size to use
initialTextThe initial text of the sprite

Method Detail

centerAt
public void centerAt(
    Point2D p
)
Sets the position of the text sprite so that it is centered at the given point.
Parameters:
pThe center point
centerAt
public void centerAt(
    float x,
    float y
)
Sets the position of the text sprite so that it is centered at the given point.
Parameters:
xThe x coordinate of the center point
yThe y coordinate of the center point
getFont
public final Font getFont()
Gets the current font assigned to this TextSprite.
Returns:
The assigned font
getText
public final String getText()
Gets the string representation of the text currently displayed for this TextSprite. Keep in mind that this method returns a newly created String and can have memory overhead.
Returns:
The string representation of the current text
isTextEmpty
public final boolean isTextEmpty()
Determines whether this TextSprite represents an empty text. This is a faster method than to retrieve the text and examine it manually.
Returns:
true if the text is an empty string, and false otherwise
render
public final void render(
    RenderingContext ctx,
    int flags
)
Renders the visual content.
setFont
public final void setFont(
    Font font
)
Assigns a new font to this TextSprite.
Parameters:
fontThe new font to be assigned
setRTL
public void setRTL(
    boolean isRtl
)
Sets the right-to-left state of this TextSprite. If a text sprite is right-to-left, its characters will flow from right to left.
Parameters:
isRtltrue will make this sprite right-to-left and false will make it left-to-right
setText
public final void setText(
    String value
)
Sets the text on this TextSprite. Changes will take effect immediately.
Parameters:
valueThe string representation of the new text