Module blitwizard.font

The font namespace allows to draw bitmap fonts.

One bitmap font is included and can be used by submitting "default".

Keep in mind when releasing your game: please note this module is implemented in the blitwizard templates, so it is unavailable if you don't ship the templates with your game.

Info:

  • Copyright: 2013
  • License: zlib
  • Author: Jonas Thiem (jonas.thiem@gmail.com)

Class text

text:new (text, font, scale, camera, width, glyphWidth, glyphHeight, glyphsPerLine) Create a text object.
text:destroy () Destroy a text object again.
text:move (x, y) Move the text object to the given screen position in game units (0,0 is top left).
text:getPosition () Get the current top-left position of the text object.
text:getGlyphDimensions () Get the size of a glyph in game units.
text:setZIndex (zindex) Set the Z index of the text block (see blitwizard.object:setZIndex).
text:setVisible (visibility) Set the visibility of a text block.
text:width () The width in game units of the complete text block.
text:height () The height of te text block in game units.


Class text

The text object represents a rendered text. Create one using blitwizard.font.text:new. You can destroy it again by using blitwizard.font.text:destroy.

Usage:

  -- Create a text saying "Hello World" in the upper left corner
  -- (with a scaling of 2, so twice the normal font size)
  local myText = blitwizard.font.text:new("Hello World",
    "default", 2)

  -- Move it a bit away from the upper left corner:
  myText:setPosition(0.6, 0.6)
text:new (text, font, scale, camera, width, glyphWidth, glyphHeight, glyphsPerLine)
Create a text object. You submit a string, a font bitmap path (can be "default" for standard font), and various layout information like maximum width of the text block in game units (will result in line wraps if text is too long) and font scaling.

Parameters:

  • text string the text you want to display
  • font string (optional) the path to the bitmap of the bitmap font you want to use. You can also specify nil or "default" for the default font
  • scale number (optional) the scale of the font. 1 for normal scale, anything else for scaling up (larger)/down (smaller). How large that turns out depends on how large the font originally was - give it a try!
  • camera userdata the game camera to show the text on. Specify nil for the default camera (first one from blitwizard.graphics.getCameras)
  • width number (optional, pass nil if you don't want to specify) the intended maximum width of the text in game units. If the rendered text was to exceed that width, line wraps will be applied to prevent that - it turns into a multi line text with multiple lines.
  • glyphWidth number width of a glyph in the bitmap font in pixels. Optional for the "default" font.
  • glyphHeight number height of a glyph in the bitmap font in pixels. Optional for the "default" font.
  • glyphsPerLine number the amount of glyphs per line, if not texture width divided by glyphWidth. Optional for the "default" font.

Returns:

    table returns text object
text:destroy ()
Destroy a text object again. (If you don't do this, it will stay on the screen forever!)
text:move (x, y)
Move the text object to the given screen position in game units (0,0 is top left).

Parameters:

  • x number new x position in game units (0 is left screen border)
  • y number new y position in game units (0 is top screen border)
text:getPosition ()
Get the current top-left position of the text object.

Returns:

  1. number x coordinate
  2. number y coordinate
text:getGlyphDimensions ()
Get the size of a glyph in game units.

Returns:

  1. number x dimensions of glyph (in game units!)
  2. number y dimensions of glyph (in game units!)
text:setZIndex (zindex)
Set the Z index of the text block (see blitwizard.object:setZIndex).

Parameters:

  • zindex number Z index
text:setVisible (visibility)
Set the visibility of a text block. This allows you to temporarily hide a text object (see blitwizard.object:setVisible).

Parameters:

  • visibility boolean true if visible, false if not
text:width ()
The width in game units of the complete text block.
text:height ()
The height of te text block in game units.
generated by LDoc 1.3.11