Text rendering is the process of displaying text on the stage, usually in ways more flexible than the use of the say block or stage monitors.

There are many ways this can be achieved, including:

  • Using a set of sprite costumes to display images of letters, either cloned or stamped.
  • Using pen lines to draw letters.
  • Using pen dots to make a bitmap image or dot matrix.


Stamped Costume Method

An example of stamped text.

The examples in this section use the Stamp block. It is possible to achieve the same visual effect by creating clones: Simply replace each Stamp block with a Create Clone of (myself) block. However, the use of clones has two disadvantages:

  1. Creating and managing clones is prone to lag.
  2. A maximum of 300 clones can be displayed simultaneously.

Setup

Firstly, obtain or create costumes for each character. Each costume should be named the character it represents. Costume names are case sensitive so you can have a distinct character for "A" and "a", for example. If rendering spaces between words is needed, don't forget to also create an empty costume named with a space.

Script

define render text (text) at x: (text x) y: (text y)
go to x: (text x) y: (text y) // move to text start position
set [i v] to [1] // counter
repeat (length of (text)) // loop over the characters in the string
  switch costume to (letter (i) of (text))
  stamp // leave an image of this letter
  change x by (10) // move to next letter position
  change [i v] by (1) // increment counter to go to the next character
end
Note Note: Set the custom block to "run without screen refresh" to draw all the text instantly.

The script assumes all the characters have the same width. If not, see "Varying Letter Widths" below.

Varying Character Widths

This section builds on the tutorials above.

To accomplish this, create a list to store the widths: (character widths::list). For each costume, enter its width measurement into the list. Add 1 or 2px to the number so the characters can have small gaps between each other. Make sure that the costume number corresponds with the list number!

In the text rendering script, replace:

change x by (10)

With:

change x by (item (costume [number v]) of [character widths v])

To test that all of the letter widths are correct, it can be helpful to print out every letter and character supported as well as some sentences.

Example Projects

Pen Drawing Method

An example of pen text.

This is a complicated method requiring the shape of each character to be stored in a list as a series of strokes. Case sensing is often handled with costumes so there is some similarity with the stamped method above.

Example Projects

See Also

Cookies help us deliver our services. By using our services, you agree to our use of cookies.