Labels - A Much Faster Way of Drawing Text

Jon

  • *
  • Posts: 17523
There are two ways to draw text in iStencyl.

1) Draw it explicitly using the drawing blocks.

Advantages: Easy to get up and running.
Disadvantages: Slow. Inflexible beyond positioning.

2) Use labels

Advantages: Fast. Can treat label like an actor (tween, move, rotate, fade, etc.)
Disadvantage: More work to setup.


Labels are basically an addon to actors that makes them draw text that persists across frames and can be updated as necessary, rather than continually drawn on demand, which can gobble up precious CPU cycles.

You don't actually need to worry about the innards of this - just search for my "Label for iOS" behavior on StencylForge. Attach it to a blank actor with a single blank animation (1 frame, transparent) and stick the actor on screen wherever you'd like.

The behavior comes with custom blocks that you can use to update the label's text and font from other behaviors. The nice thing is that since a label is an addon to an actor, you can do everything to an actor that you normally would - this makes labels very versatile!

That's it! If your game uses a lot of text, you'll see a noticeable framerate improvement.

« Last Edit: August 17, 2011, 12:14:38 am by Jon »

fanstudio

  • Posts: 201
Can you provide us with more info on how we can setup these labels?

For example I would like to setup a certain position and font size and a background to this label...

Is it possible?

Jon

  • *
  • Posts: 17523
We'll write a micro article on this, but it's pretty simple.

1) Make a dummy actor. Give it a blank single frame animation.
2) Grab the Label for iOS behavior from StencylForge and attach to the actor.

Self explanatory after that. Let me know if you have trouble.

fanstudio

  • Posts: 201
I did that and the text appears but at a wrong size...I think it's around 48px or something and it looks pixelated...

I wanted to have the option to change the font size from that Label for iOS behavior.

Jon

  • *
  • Posts: 17523
You can't change the font size because they're bitmap fonts. What you'd need to do is define a new font and switch to that instead.

Fonts shouldn't be scaling at all unless the actor's been told to scale.

fanstudio

  • Posts: 201
I have imported a custom font that I want to use but is way too big even tough I set the size to 16x.

Jon

  • *
  • Posts: 17523
Feel free to attach a small test game with just the font and the label usage.

fanstudio

  • Posts: 201
I managed to set the size that I wanted and it looks alright now :)