-
-
Notifications
You must be signed in to change notification settings - Fork 490
font
font(text, x, y, [transcolor], [char width], [char height], [fixed=false], [scale=1], [alt=false]) -> text width
- text : The string to be printed.
- x, y : Coordinates of print position.
- transcolor : The palette index to use for transparency.
- char width : Distance between start of each character, in pixels.
- char height : Distance vertically between start of each character, in pixels, when printing multi-line text.
- fixed : Indicates whether the font is fixed width (defaults to false ie variable width).
- scale : Font scaling (defaults to 1).
-
alt : If set to
true
, the second 128 foreground tiles (#384–511) are used for the font rather than the first 128 (#256-383) as if set tofalse
.
- text width : Returns the width of the rendered text in pixels.
This function will draw text to the screen using the foreground spritesheet as the font. Sprite #256 is used for ASCII code 0, #257 for code 1 and so on. The character 'A' has the ASCII code 65 so will be drawn using the sprite with sprite #321 (256+65). See the example below or check out the In-Browser Demo.
- To simply print text to the screen using the system font, please see print.
- To print to the console, please see trace.
- There may never be more than 128 ASCII characters within a single font() call. The first 32 ASCII characters, which serve as object characters, are unused by text, therefore effectively only 96 characters are available for text.
For list of ASCII codes, please refer to this link.
-- title: Font Demo
-- author: paul59
-- desc: Shows the working of font()
-- script: lua
function TIC()
cls()
-- The # character is ascii code 35
-- so the sprite with ID 256+35 (#291)
-- will be used to draw that character
-- A and B have ascii codes 65 and 66.
-- Sprites 256+65 (#321) and 256+66
-- (#322) will be used to draw those
-- letters
font('#AB',20,20,2,9,9,true,3)
-- The above prints '#AB' at position
-- 20,20. The sprites use color 2 as
-- transparency colorkey, are drawn 9
-- pixels apart with fixed width and
-- scaled up by a factor of 3
end
To use the font() function while keeping the tiles used by the custom font minimal, one may opt to manipulate RAM to draw sprites at a lower bit depth. Whichever blit segment local indexing parameter is set, the first foreground tile page relative to the local indexing parameter will be used to render the font() function. Positions of ASCII characters relative to a given sprite page remains the same as in 4 bits per pixel (i.e. if blit segment is set to 8, then the characters use sprites within a 16×16 tile perimeter starting with #1024).
TIC-80 tiny computer https://tic80.com | Twitter | Telegram | Terms
Built-in Editors
Console
Platform
RAM & VRAM | Display | Palette | Bits per Pixel (BPP) |
.tic
Format | Supported Languages
Other
Tutorials | Code Snippets | Libraries | External Tools | FFT
API
- BDR (0.90)
- BOOT (1.0)
- MENU
- OVR (deprecated)
- SCN (deprecated)
- TIC
- btn & btnp
- circ & circb
- clip
- cls
- elli & ellib (0.90)
- exit
- fget & fset (0.80)
- font
- key & keyp
- line
- map
- memcpy & memset
- mget & mset
- mouse
- music
- peek, peek4
- peek1, peek2 (1.0)
- pix
- pmem
- poke, poke4
- poke1, poke2 (1.0)
- rect & rectb
- reset
- sfx
- spr
- sync
- ttri (1.0)
- time
- trace
- tri & trib (0.90)
- tstamp (0.80)
- vbank (1.0)