Wednesday FAQs: Display Text Objects

Wednesday FAQs: Display Text Objects

FAQ IconIt’s Wednesday and time for another frequently asked questions (FAQs) session. Here are some FAQs about display text objects.

1. I’m creating lots of display.newText objects and it’s slowing down my app. Why?

It may seem like text is a simple thing to display on the screen but it can be very complicated and time consuming. When you create text with display.newText, the text must be first converted into a bit map and then sent to openGL so it can be rendered on the screen. The larger the text (in the number of character and font size), the longer this process takes. It also consumes texture memory just like displaying images.

2. I’m moving text around on the screen, will that slow down my app?

Moving or scaling text objects does not slow down Corona SDK. If you are changing the text, the bit map needs to be recreated, which can impact the frame rate. The same is true when changing the font size or the font type. These all require a new bit map and may affect performance.

3. I’m using display.newText and see a white or black block where the text should be. What’s wrong?

The black or white block is what you see when the text exceeds the texture limit of the device. Since text objects are converted to bit maps before being displayed, long text strings with a large font size can easily exceed the texture memory limit of some low-end devices. The solution is to limit the amount of text displayed in a single display.newText object. You should break up large text objects into multiple text objects.

4. How do I align text?

Text Justification
Starting with Daily Build 1143 we added text alignment to display.newText. You can specify “left“, “center” and “right” justification. The only limitation is you can’t change the justification after the text object has been constructed.

When we added text justification to display.newText, we changed the way parameters are supplied to the function. The parameters are now sent in a Lua “option” table instead of as individual parameters. display.newText still supports the legacy call, but you can’t use it to justify the text. Be aware that if you call display.newText with the new option table, you specify x and y values, which reference the center of the text object and not left and top used in the legacy call.

In order for text justification to work, you must supply the width parameter. If the height parameter is not supplied, it’s assumed to be 0 (this may change in the future). Left justification is assumed if no justification is specified.

Text justification also works with custom fonts but you must install the fonts on the Mac or Windows simulator in order to make it work.

5. Does display.newEmbossedText work with justification?

Currently, text justification for display.newEmbossedText objects is not implemented. We hope to have it in a Daily Build soon.

That’s it for today’s questions. I hope you enjoyed them and even learned a few things.

tom
5 Comments
  • Lerg
    Posted at 14:20h, 26 June

    How about adjusting line spacing in display.newText and others in the core?

  • Tom
    Posted at 23:18h, 26 June

    Would be nice to have 2 features:

    Related to text:
    – simple version of display.newText for showing score etc so with numbers only and with prerendered images etc… without need to render it every time. This would be nice to have timers or score counters with very fast update time.

    Not related to text:
    – make a screenshot feature inside Corona Simulator, i miss this a lot on Windows (on Mac this is build in OS).

    Tom

    • Dennis Koble
      Posted at 11:12h, 27 June

      You can of course always use Alt-Prt Scr to capture the Corona window.
      I use it all the time and then paste it into mspaint.exe and save out as a png file.
      Not quite what you asked for but it is quite useful.
      -Dennis

  • hangn
    Posted at 03:35h, 28 June

    I’m trying to display long text but I’m seeing white blocks. I know I have to create for each line text object. Can you open source the way corona wraps text? I mean a function that we pass the text, font, size and then break it into a table.

  • helios narcissus
    Posted at 03:04h, 29 June

    which is better to use then in a hangaroo game??

    a changing value of display.newText
    or
    letter sprites?