Username or E-mail
Password (Forgot?)
New? Sign Up
Join or Sign In
Forums Stencylpedia Stencyl TV Translations Go Pro - Plans & Pricing Download Stencyl


Switch to Book Layout

1: Getting Started

  • Getting Started
  • Crash Course
  • Crash Course 2
  • StencylForge

2: Building Logic

  • What is a Behavior?
  • Creating a Behavior
  • Attributes
  • Game Attributes
  • Attribute Types
  • Events
  • Our Behaviors

3: Actors

  • What are Actors?
  • Animations
  • Motion & Forces
  • Physics
  • Controls
  • Collisions & Groups
  • Killing vs. Recycling
  • Tweening
  • Effects
  • Chapter 3 Challenge

4: Scenes

  • Scene Basics
  • The Camera
  • Tilesets
  • Regions
  • Drawing Text & HUDs
  • Changing Scenes
  • Music, Sounds & Channels
  • Backgrounds
  • Customizing Actors
  • Chapter 4 Challenge

5: Game Mechanics

  • Saving
  • Pausing
  • 3rd Party Services
  • Web Requests

6: Advanced Topics

  • Get/Set Attributes
  • Custom Events
  • Blending Modes
  • Lists
  • Custom Blocks
  • Continuous Collisions

7: Testing & Tuning

  • Testing Games
  • Optimizing Performance 1
  • Optimizing Performance 2

8: The Last 10%

  • Flash Publishing
  • Standalone Apps
  • iOS App Store
  • Chrome Store
  • Making Money

M1: Mobile - Intro

  • Getting Started
  • Testing on your Device
  • Flash -> iOS Guide

M2: Mobile - Basics

  • Atlases
  • Drawing Text
  • Retina Display
  • Accelerometer
  • Joystick
  • Universal Games

M3: Mobile - Services

  • iAds
  • Game Center
  • In-App Purchases

M4: Mobile - Publishing

  • Debugging
  • Publishing to the App Store
  • Optimizing Performance
  • Promoting your Game

A: Troubleshooting

  • Showstoppers
  • General FAQ
  • iOS FAQ
  • The 90% Memory Warning
  • Recovering Broken Games
  • Can't Export to SWF
  • Reloading Documents
  • Generating Logs
  • Flash Security Settings
  • How to Report Bugs

B: How-To Guides

  • Importing Assets
  • Scene Designer
  • Code Mode
  • Font Editor
  • Pencyl (Image Editor)
  • Tile Editor (Shapes)
  • Game Cleaner

C: Reference

  • Glossary
  • Block Reference
  • Useful Shortcuts
  • Stencyl API

D: Resources

  • Stencyl TV
  • Abigayl's Guides
  • Giving Critiques
  • Creating Extensions
  • Translating Stencyl
  • Credits

3.0 Drafts (In Progress)

  • What's New in Stencyl 3.0?
  • Setup (Android)
  • Setup (Desktop)
  • Setup (iOS) - Concepts
  • Setup (iOS) - Mac
  • Setup (iOS) - Windows
  • Testing iOS on Windows
  • iOS Troubleshooter

  • Mobile App Scaling
  • Full Screen Mode
  • Simple Physics
  • Backgrounding an App

  • iOS App Store
  • Mac App Store
  • Windows Store
  • Google Play
  • HTML5

  • Android Ads
  • Android Purchases (WIP)
  • 4" Form Factor (iPhone 5)
  • Mobile Input
  • Mobile Features

  • Extending the Engine
  • iOS / Android Extensions
  • Developing the Official Extensions
  • Developing the Engine

  • iAds (Revised)
  • Game Center (Revised)
  • iOS Purchases (Revised)
  • Atlases (Revised)
  • Drawing Text (Revised)
  • Joystick (Revised)
  • Accelerometer (Revised)
  • Sounds (Revised, WIP)
  • Debugging (Revised, WIP)
  • iOS Performance (Revised)
Level: Beginner

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.

 

Contents

  • Fonts
  • Creating Fonts
  • Drawing Text
  • HUDs
  • Example: Drawing the Score
  • Labels & Mobile Games
  • The Future

 

Fonts

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.


Pros

  • They look consistent (and great!) regardless of device or hardware.
  • They draw quickly.
  • You can apply more styles to them.


Cons

  • You can’t grow them at runtime without ruining quality. (You have to create a new font for them)
  • They sometimes take up more disk space.

 

Creating Fonts

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.


Drawing Text

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.

 

HUDs (Heads Up Displays)

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.

 

Example: Drawing a Timer


(Controls: Left/Right/Up to jump)
 

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.


Walkthrough - Adding a Timer

1) Open the demo project. This project is mostly built up (run it!). All you need to do is create the Timer feature.

2) Open up the (only) Scene and flip to the Events tab.

3) Add a Number attribute called “Time” - and make it hidden.

4) Add a “Every N Seconds” event. Make it do the following.

What does this do? This increments the timer once per second. It also anchors the actor to the screen, as explained in the previous section.

5) Add a “When Drawing” event. Make it do the following.

What does this do? This draws the current time, based on the “time” attribute we created earlier.

6) That’s it! Run the game, and you should now notice it drawing the timer, just like in the demo above.

 

Mini-Challenges

1) Tweak the timer to increment twice a second.
2) Show the timer on the right side of the screen.
3) Show the timer in the center. Properly account for cases where the text may be shorter or longer.

 

Labels & Mobile Games

In mobile games, drawing text directly to the screen can impact your game’s framerate by up to 50% or more. We recommend using Labels instead.

(Don’t do this in your iOS games)

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.

View our article on Labels to learn how to create them and set them up.

The reason why Labels are faster is because they only update when their text changes. In most cases, text never changes or changes less frequently than each frame. For this reasons, you should always use Labels for your mobile game.

 

The Future

Currently, Labels are only available in mobile games. We plan to make the Labels feature universal and to build it directly into the toolset itself, along with built-in support for alignment and line-wrapping.

You’ll be able to place Labels inside scenes, just like you’d type text into Photoshop. 


Summary

  • Stencyl uses bitmap fonts to draw text to ensure good performance and consistent results.
  • HUDs are graphical displays of information that display on top of everything else and do not obey the camera.
  • Use Labels for mobile games for best performance.


Challenge: Dialog Box

One of the most common uses of text is drawing dialog boxes.

Create a simple system for displaying dialog, in which you specify a List of text (1 sentence per entry) to display.

The dialog should display 1 sentence at a time, and the player has to hit a key to proceed.

Super Challenge: Bonus points for auto-wrapping text and displaying a little blinking arrow to indicate to the player that the sentence is “finished” and the system is waiting for the player’s go to continue.


Last Updated: 2013-03-11 by Jon

23244 have read this article
Disclaimer: The Stencyl Team does not actively monitor comments on articles. If you're seeking help for your game, please ask a question on the forums. Thanks!
9 Comments
Stencilian
So far I have not seen any way of downloading version 3 ?
Meanwhile I can draw a rectangle at mouse down (fill rect at x y with w h) but cannot get it to stay on the screen. ? How can we do what SCRATCH does - detect a particular color from lines (PEN DOWN) drawn on the screen?

0 1 week, 6 days ago
weilies
hi there, does the S3.0 come with line-wrap feature?
Also, it seems like it's not possible to set font color (in iOS), will this issue be resolve as well?

0 1 month ago
aBanana1234
I'm new to stencyl and I really want to add dialog to the being of my game but I have no idea how.. I would like an article on how to add dialog(unless there already is an article on dialog?) Thanks
0 1 month, 3 weeks ago
pangtee
What is the maximum length of text that i can input using TEXT?
Can i create a page or a few pages of text?
Thanks.

-1 7 months, 5 days ago
Pendertuga
Instead of Diag boxes being a challenge you guys should just tell people how to do it. I'm sure many people would like to know.
4 8 months, 5 days ago
PizzaLovesYouYeah
how do you make a dialog box appear when the main character nears another character?
1 9 months, 5 days ago
Losk of the ring
i do have a question... is it possible to make the actor drawing instead of a scene? if it's not possible, why do "when drawing" box is displayed in the "actor Behavior's creation"? help me please... thanks
p.s. what version of stancyl do these tutorials refer to? stencyl 2?

1 1 year, 1 month ago
Jon
Updated with the full demo. Coverage of all drawing functions will take place in a separate/future article.
1 1 year, 1 month ago
solleader
love the challenge <3 great article anyway, very useful, it wuold be nice if it can explore all of the stencyl drawing featurem
-1 1 year, 1 month ago



Commenting Guidelines

Sign In to Comment

Make Games

  • What is Stencyl?
  • Roadmap
  • Pricing

Play

  • Arcade
  • Showcase

Community

  • Forums
  • Chat
  • Translations

Help

  • Stencylpedia
  • Stencyl TV

About Us

  • Blog
  • Contact Us
  • Press
  • Privacy
Follow Stencyl on Twitter



© 2013 Stencyl, LLC.