Contents
- Introduction
- Installing the Labels Extension
- Creating a Label
- Changing a Label's Text and Font
- Moving a Label Around
- FAQ
Introduction
Most games draw text to the screen using our draw blocks. This remains the recommended way of doing things.
However, in some games, it would be nice if text were like an actor, so you could easily tween its position, rotation and opacity. That's what labels are for.
Labels are a special kind of actor that can display text. You can specify a font and text to draw for this actor. Like any other actor, a label has a position, rotation, opacity, and can have behaviors attached to it.
Installing the Labels Extension (Stencyl 3.0 and later)
In Stencyl 3.0+, labels are now housed under an optional extension, rather than a behavior on StencylForge.
1) Go to Settings > Extensions and enable the Labels extension.
2) Close and reopen your game.
3) Open up any Behavior or Event. You'll now find the Label blocks under the Custom category.
How to Create a Label
Labels are mounted to actors. To exist, you must mount them to an actor by applying a label block to them. The following describes the best practice for creating labels.
1) Create a blank Actor with a blank Animation.
2) Add the actor to the desired scene. If you find it inconvenient that the Actor is "invisible", you can assign a dummy animation to the Actor. It won't display in-game.
3) Through events or behaviors, attach a label to the actor using the attach label block under the Custom category.
How to Change a Label’s Text and Font (and more)
After you have attached a label to an actor as decribed above, you can perform operations on it, including...
- Change the text
- Change the font
- Enable text wrapping
- Set the alignment to left/center/right
These blocks are located under the Custom category, the same one housing the attach label block.
Here's a complete example of the whole process of attaching a label to an actor (via the when created event) and setting some properties.
How to Move a Label Around (and more)
Labels are actors!
You can move them around just like you’d move a regular actor around, setting the label’s position, setting the label’s speed, or a using motion tween, for example.
You can tween them in other ways - spin them around, fade them out and whatever else suits your needs.
FAQ
Do labels support text wrapping? How about alignment?
Yes, they do. There's a block for both of these in the Label extension.
Has someone written up a dialog system?
Yes. See this.
How do I support localization?
See this ongoing discussion for ideas.
The gist is that it's easiest if you ask your user what language they prefer, set that in a text Game Attribute and then alter your text based on that value of the Game Attribute. There are ways to automatically pull the locale, but these require code. The discussion covers the exact details.
11 Comments
If you just type in "label" in the search bar, you will find in the Extensions button
0
I have installedg the Labels Extension ?but still can't find the Label blocks under the Custom category.what should I do?
0
For those of you using the Label Extension and code blocks to create new lines etc, though the documentation says \n is the newline character its actually \\n so the syntax is:
actor.say("Label","_ customBlock_SetLabelText", ["Line1 \\n Line2"]);
That will then display:
Line1
Line2
Using this type of logic can be useful for the credits in your games.
1
I've updated the article for 3.0 and tried to address most of the issues raised in the update.
0
Losh started a topic here for those who want to localize games. (http://community.stencyl.com/index .php/topic,19118.0.html)
0
can you explain in the "how to change a label's text and font" category, where exactly to put those blocks?
this process is not working at all for me :/
1
It's possible to have multiline Text, Alignment and something for i18n?
Would like to use iStencyl for some Multimedia eBook iPad app like one we have already created (http://goo.gl/tyvK7)
1