Text
There are four ways to put words on the stage:
| What | How | For |
|---|---|---|
| a speech bubble | say("Hi!"), think("Hmm") |
a sprite talking |
| a band at the bottom | display("Level 2") on the stage |
hints, short messages |
| a variable | showVariable("score", () -> score) |
the score, lives, time |
| a text object | new Text(...) |
titles, labels, anything else |
Speech bubbles
say("Hi!") shows a bubble until the next say. say("Hi!", 2) takes it away
after 2 seconds. say("") removes it. think works the same way, with a
thought bubble.
Showing a variable
A Java variable has no checkbox, as in Scratch. showVariable puts it in the
top left corner and keeps it up to date. Press space:
() -> presses means "ask for presses whenever the display is drawn". That is
why it stays up to date.
Text objects
A Text is placed like a sprite. You choose its size, colour and font:
new Text(text, x, y, width):widthis where lines wrap,0for never.showText("...")changes what it says.setTextSize,setTextColor,setBackgroundColor,setAlign(TextAlign.CENTER).- A fifth argument gives it a style:
TextStyle.BOX,SPEAKorTHINK. hide(),show()andremove()work as for sprites.
Fonts
Put a font file (TTF or OTF) into your project and use it for every text:
Text.useFont("assets/my-font.ttf"); // in main, before new Window(...)
Or only for one text: title.addFont("title", "assets/my-font.ttf"), then
title.switchFont("title").
Free fonts: Google Fonts. Check that the licence allows what you want to do with your game.