SSH Productions: Module documentation for SpriteFont.zip

Module: SpriteFont 1.2, by SSH

Write text using sprites rather than AGS fonts

Download SpriteFont as a zip file

Author

Andrew MacCormack (SSH)

Please use the PM function on the AGS forums to contact

me about problems with this module

Abstract

Display text using a font comprising sprites. The text can be

drawn on background, dynamic sprite or overlay and BG text can

be at any angle.

Dependencies

AGS 2.72beta4a or later. v1.02 should be used for AGS 2.71

Digraphs module will be automatically run on strings passed in,

if the Digraphs module precedes this one in the module manager

Functions

 function SpriteFont.SetFontSprite(char c, int spr);

A spritefont needs to be set up with the appropriate sprites for each

character. These can be set individually with this function, or can be

stored in a view, character, or in files using the following functions:

 function SpriteFont.FontSpritesFromView(int v, char firstchar, optional char numsprites);

This function goes through the sprites in the specified view and adds them to

the spritefont staring at character firstchar. Either this runs until no more

sprites are left in the view, or until the optionally specified number of sprites

are added.

 function SpriteFont.FontSpritesFromChar(Character *c, optional char firstchar, optional char numsprites);

RECOMMENDED method of setting up a spritefont: loads a spritefont with sprites

from the Normal view of the specified character. The first character of the font

that uses the first sprite can be derived from the Character's X position or passed

as the argument firsthchar. This runs until no more sprites are left in the

view, or until the optionally specified number of sprites are added. Since

characters can be exported, they can be used as fonts if you don't mind having

a dummy character in your list.

 function SpriteFont.SetFontSpriteFromFile(char c,  String filename);

A sprite for a font can be loaded from a file: PCX and BMP formats only

 function SpriteFont.FontSpritesFromFiles(String fileroot, char firstchar, char numsprites);

A set of sprites can be loaded from files. The ASCII code will be appended to the

fileroot in decimal to get the filename for each character's sprite, starting from

firstchar and continuing for numsprites.

 function SpriteFont.GetSpriteTextRawWidth(String t);

Returns the width of the given text in pixels, unrotated

 function SpriteFont.TextOnBackground(int x, int y, String t, optional int transparent, optional int angle);

Displays the specified text at location x, y on the background, with an

optional transparency percentage (default 0) and angle (default 0, in degrees,

clockwise).

 DynamicSprite *SpriteFont.TextOnSprite(String t);

Returns a Dynamic Sprite of the given text.

 Overlay *SpriteFont.TextOnOverlay(int x, int y, String t, optional bool transparent);

Returns an overlay with the given text on it. Transparency here represents whether

the overlay has a black background or transparent.

Configuration

The CharSpacing and LineSpacing properties can be set to increase the spacing

used when printing the text. CharSpacing defaults to 0, LineSpacing defaults

to the height of the tallest character added to the font so far, so manual

modifications to this should only occur after the sprites are added to the font

Example


  SpriteFont Courier;

In addition to the licences mentioned in the modules themselves, you may choose to use the following creative commons licence if you prefer for all AGS modules and open source code resources on my site.

Creative Commons License
This work is licenced under a Creative Commons Licence.