org.newdawn.slick
Class SpriteSheetFont

java.lang.Object
  extended by org.newdawn.slick.SpriteSheetFont
All Implemented Interfaces:
Font

public class SpriteSheetFont
extends java.lang.Object
implements Font

A font implementation that will use the graphics inside a SpriteSheet for its data. This is useful when your font has a fixed width and height for each character as opposed to the more complex AngelCodeFont that allows different sizes and kerning for each character.

Author:
Onno Scheffers

Constructor Summary
SpriteSheetFont(SpriteSheet font, char startingCharacter)
          Create a new font based on a SpriteSheet.
 
Method Summary
 void drawString(float x, float y, java.lang.String text)
          Draw a string to the screen
 void drawString(float x, float y, java.lang.String text, Color col)
          Draw a string to the screen
 void drawString(float x, float y, java.lang.String text, Color col, int startIndex, int endIndex)
          Draw part of a string to the screen.
 int getHeight(java.lang.String text)
          Get the height of the given string
 int getLineHeight()
          Get the maximum height of any line drawn by this font
 int getWidth(java.lang.String text)
          Get the width of the given string
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

SpriteSheetFont

public SpriteSheetFont(SpriteSheet font,
                       char startingCharacter)
Create a new font based on a SpriteSheet. The SpriteSheet should hold your fixed-width character set in ASCII order. To only get upper-case characters working you would usually set up a SpriteSheet with characters for these values:
   !"#$%&'()*+,-./
  0123456789:;<=>?
  @ABCDEFGHIJKLMNO
  PQRSTUVWXYZ[\]^_
 In this set, ' ' (SPACE) would be the startingCharacter of your characterSet.

Parameters:
font - The SpriteSheet holding the font data.
startingCharacter - The first character that is defined in the SpriteSheet.
Method Detail

drawString

public void drawString(float x,
                       float y,
                       java.lang.String text)
Description copied from interface: Font
Draw a string to the screen

Specified by:
drawString in interface Font
Parameters:
x - The x location at which to draw the string
y - The y location at which to draw the string
text - The text to be displayed
See Also:
Font.drawString(float, float, java.lang.String)

drawString

public void drawString(float x,
                       float y,
                       java.lang.String text,
                       Color col)
Description copied from interface: Font
Draw a string to the screen

Specified by:
drawString in interface Font
Parameters:
x - The x location at which to draw the string
y - The y location at which to draw the string
text - The text to be displayed
col - The colour to draw with
See Also:
Font.drawString(float, float, java.lang.String, org.newdawn.slick.Color)

drawString

public void drawString(float x,
                       float y,
                       java.lang.String text,
                       Color col,
                       int startIndex,
                       int endIndex)
Description copied from interface: Font
Draw part of a string to the screen. Note that this will still position the text as though it's part of the bigger string.

Specified by:
drawString in interface Font
Parameters:
x - The x location at which to draw the string
y - The y location at which to draw the string
text - The text to be displayed
col - The colour to draw with
startIndex - The index of the first character to draw
endIndex - The index of the last character from the string to draw
See Also:
Font.drawString(float, float, String, Color, int, int)

getHeight

public int getHeight(java.lang.String text)
Description copied from interface: Font
Get the height of the given string

Specified by:
getHeight in interface Font
Parameters:
text - The string to obtain the rendered with of
Returns:
The width of the given string
See Also:
Font.getHeight(java.lang.String)

getWidth

public int getWidth(java.lang.String text)
Description copied from interface: Font
Get the width of the given string

Specified by:
getWidth in interface Font
Parameters:
text - The string to obtain the rendered with of
Returns:
The width of the given string
See Also:
Font.getWidth(java.lang.String)

getLineHeight

public int getLineHeight()
Description copied from interface: Font
Get the maximum height of any line drawn by this font

Specified by:
getLineHeight in interface Font
Returns:
The maxium height of any line drawn by this font
See Also:
Font.getLineHeight()


Copyright © 2006 New Dawn Software. All Rights Reserved.