1: Getting Started
2: Building Logic
5: Game Mechanics
6: Advanced Topics
7: Testing & Tuning
8: The Last 10%
M1: Mobile - Intro
M2: Mobile - Basics
M3: Mobile - Services
M4: Mobile - Publishing
B: How-To Guides
3.0 Drafts (In Progress)
Drawing Text & HUDs
Text is an essential element of most games. Text conveys information to the player in real-time. This article will teach you how to draw text to the screen and how to style it.
Fonts are a term used to describe the styling of text. Stencyl uses bitmap fonts to display text. Bitmap fonts are a special kind of font in which the font is pre-rendered to pixels.
To create a font, use our Font Editor. You can create a new font by heading to File > Create New > Font.
This will bring up the Font Editor. Our Font Editor lets you style fonts to your liking and even lets you import a custom TrueType (TTF) font.
If you'd like to learn more about it, read our Font Editor article.
The easiest way to draw text is to draw it directly via the “when drawing” event.
Set a font before drawing any text.
If you don’t do this, the text will draw in black and the default, built-in font, which is undesirable for most games. On iOS, the game may crash if no initial font is set.
A HUD (heads up display) is a transparent, graphical dashboard that displays on top of everything else.
HUDs usually display statistics. Think of them as the dashboard on your car, the one that displays how fast your car is going, how much gas you have left, the outside temperature, etc.
One aspect of HUDs that’s unique is that they don’t follow the camera. They always draw at the same place on screen, regardless of where you are. Think of them as being this piece of glass that's on top of the game but not part of the game itself.
How to make an Actor "disobey" the camera
Have you seen this block? (Actor > Drawing)
The ability to anchor an actor to the screen was made specifically for creating HUDs. As the name suggests, anchoring an actor makes the actor ignore the camera, so it always is drawn at the same place on screen.
Note: HUDs aren’t a part of Stencyl or a specific feature. They’re just a common aspect of most games that they deserved special mention and to establish how to make them using the anchor block.
In the next example, we’ll talk about how to do something common: drawing a timer.
Download the Project
- Unzip and stick the project into your Games directory as "Text Demo"
- Don't know where your Games directory is? Click the "View Games Directory" button at the bottom of the Welcome Center (the first screen you see after opening Stencyl)
Goal: We want to draw the Timer shown in the demo.
- The timer counts up once per second.
- As you walk towards the right, the timer stays at the same spot on screen.