FlxText performance questions

  • Hello everyone, I have a sightly advanced questions about FlxText and its inner working.

    I'd like to make a textbox with the text appearing one or more characters appearing per seconds, the logic behind isn't unknown to me as I already done some for some projects, but I wondered about the performance of such structure on Flixel.

    So, I'm figuring right now two options :

    1. A static text (understand no character-based animation like character rotation or stuff) system, where the text lines would be two FlxText where I would update their contents on the fly each update tick.
    2. Use a FlxText per character, allowing me more flexibility but to the expense of more memory, CPU and possibly GPU usage.

    Now, it's time for questions:

    • Let's say in the first solution, I'd add a character per frame, what are my options to determine in advance the pixel size of a string without building it? If I could, for instance, add character or word wrapping, it could be very helpful.
      • If I manually set fieldWidth, can I still get the actual area dimension used by the characters? It could work as a workaround for the previous question but would be a dirty one.
    • Wouldn't be storing a FlxText per character be radically slower and heavier? Even with a FlxPool, wouldn't it be better to just use FlxSprites with an atlas in this case?

    Anyway, thank you for taking the time reading this, have a nice day, everyone.

    Edit : I realized I forgot to tell something, I have to check for the text to fit in the box. If it doesn't the text box must stop and wait for a signal to continue (putting the content of the last line in the first). That's again something I already programmed on something else totally different but I somehow think it'd help people understanding my needs.

  • administrators

    What you're talking about sounds a lot like FlxTypeText, have you seen that?


    If you want control over individual characters, something like that has apparently already been implemented in the Lycan lib:


  • I see, there are so much demos I forgot about this one, sorry. Well this demo shows me another way to do it, but it brings back globally to my first solution, which is editing one (or more) FlxText. Something I should add is that I need to sometimes break the flow of the box when it's asked or when the textbox is full. (I possbily have a control system in the works to embed stuff like querying entities' names or pictures/sprites) That's why I wanted to run my own version of such system, I already have one working in C++ based on the second solution. (Beware, it's quite hacky, I have its mechanisms in my mind, I'll just redo it from scratch for a cleaner version).

    Lycan's system, even if half-implemented, is related to my second idea : having a list of sprites used as letters. I have to admit this is the solution I'm preferring as it offers me the ability to mess with the letters independently of the whole line. I'll guess I'll use option 2. Thanks for the suggestions. I just now wonder about the performance impact of FlxText against using atlases, but I do think I should take a look more at Flixel's sources, shouldn't I? Hehe.

    At least, thanks for replying to me. have a nice day and good luck with developing this library!

Log in to reply

Looks like your connection to HaxeFlixel was lost, please wait while we try to reconnect.