Eng:Text Rendering

Text rendering is a different way of making a sprite "say" something in a more realistic way. This rendering makes it seem as if the words are appearing to be typed rather than posted.

Text Rendering a Dialog Bubble
One of the ways to take advantage of text rendering is through the use of the say block. This process is simple and requires two variables, "item" and "text" to be made, along with a custom block.

render text []; delay seconds // category=custom

It is imperative that you do not check off the run without screen delay checkbox while creating the custom block. If so, the typing effect will be lost. In this block, the first input is for text or numbers to be rendered. The second input affects how long the sprite waits before doing something else like rendering more text or going onto other things.

Defining the Custom Block
Now, create the defining script for the custom block:

Define render text [string]; delay (number) seconds Set [item v] to [1] Set [text v] to [] Say [] Repeat (( length of (string)) + (1)) Say (text) Set [text v] to (join (text)(letter (item) of (string)) Change [item v] by (1) End Wait (number) secs Say []

Text Rendering with a Sprite
The following sections will discuss text rendering via stamping. It is possible to use cloning instead of stamping. Simply replace any Stamp blocks with Create Clone of (myself) blocks. A downside to using cloning is that it might lag the script.

Without Case-Sensitivity
First off, create 26 costume of the letters a to z, and make sure each costume has the same lowercase name as the letter they represent. If you want to use any letters/characters outside of a to z, they will each require a costume whose name is the same as the character. Some characters that would be useful to add include: punctuation, numbers, and more.

The first step is to create a custom block and to go through each letter of the message to be rendered. Our custom block will take three parameters. The text to be rented, the x position where it will be rendered, and the y position where it will be rendered. It should also run without screen refresh.

Next, we will switch to the appropriate costume, and stamp it.

Define render text [text] at x: (x pos) y: (y pos) go to x: (x pos) y: (y pos) set [letter v] to (1) repeat (length of (text)) change [letter v] by (1) switch costume to (letter (letter) of (text)) change x by (10)//change this number for more space between letters end

If all characters have the same width, it is safe to stop here. If else, continue onto the section "Varying Letter Lengths"

With Case Sensitivity
For case sensitivity, follow the Case Sensing tutorial before following this tutorial. The costumes in the Case Sensing tutorial are required. If you want to use any letters/characters outside of a to z, they will each require a costume whose name is the same as the character. Some characters that would be useful to add include: punctuation, numbers, and more.

The first step is to create a custom block and to go through each letter of the message to be rendered. Our custom block will take three parameters. The text to be rented, the x position where it will be rendered, and the y position where it will be rendered. It should also run without screen refresh.

The variable letter will be used to remember which letter we are looking at.

Define render text [text] at x: (x pos) y: (y pos) go to x: (x pos) y: (y pos) set [letter v] to (1) repeat (length of (text)) change [letter v] by (1) end

Next, we switch to the appropriate case sensitive costume. Check the Case Sensing tutorial for how this is done. After we finish processing one letter, we move onto the next letter by increasing the x position.

Define render text [text] at x: (x pos) y: (y pos) go to x: (x pos) y: (y pos) set [letter v] to (1) repeat (length of (text)) change [letter v] by (1) switch costume to (letter (letter) of (text)) //if the character is lowercase, it will stay on "null" if <(costume #) = (1)> then //if the sprite never changed costumes due to the letter being lowercase switch costume to (join (character) [t]) //all lowercase costumes end in "t" or your lettered choice (refer to pattern above) end if <(costume #) = (1)> then//if the sprite still has not changed costumes ... //we have a space, a character without a costume, or a costume with an incorrect name ... //we will assume it is a space else stamp end change x by (10)//change this number for more space between letters end

If all characters have the same width, it is safe to stop here. If else, continue onto the section "Varying Letter Lengths"

Varying Letter Lengths
This section builds off of either the case-insensitive or the case-sensitive tutorials.

Because each letter (and character) can have a different width, it is sometimes necessary to take this into account to avoid large gaps between letters and overlapping letters.

To accomplish this, create a list named "Letter Lengths" For each costume that you have, enter its width (plus a pixel or two) into the list. Make sure that the costume number corresponds with the list number!

If there is a "null" costume, it also requires a number in the "Letter Lengths" list. Because the "null" costume is assumed to be a space, make sure the corresponding list number is the width of a space.

In the text rendering script, replace:

change x by (10)

With:

change x by (item (costume #) of [Letter Lengths v])

To test that all of the letter lengths are correct, it can be helpful to print out every letter and character supported.