Okay, a few questions; first of all, I'm trying to make a classic text-box that overlays the regular gameplay. Just think like text from a Pokemon game on Gameboy or something. I can't for the life of me get the text to show on top of my sprites? Is there a z-index argument I've missed somewhere? None of the text or font functions seem to have a z-index. I feel like I'm missing something really basic here, but I couldn't find anything like this in any of the example files either.
Secondly (and this is just a dream feature probably but) I'd love to be able to animate the text being "typed" out on screen, and not just pop up all at once. I could probably split the string up into chunks (or even single letters) and put them in an array and loop through them, which shouldn't be too heavy for the CPU/memory, but if there is a simpler way that would be cool.
This all depends on me solving my first problem though.
I’m not sure how you’re attempting to do it now, but this is how I do it in my game:
Set up your game sprites, probably the way you already do;
Make the text box a sprite in itself. Don’t think of sprites as “game characters”; they’re a great solution to basically every piece of graphics you’re putting on screen;
In the text sprite’s draw() callback, step through the characters one by one and add them to the drawn string. Add a timer to draw them with a delay.
That’s the high-level overview of it. If an example would be useful, I’ll see about making one.
You make a sprite with image big enough to fit text, lockfocus to the image used by that sprite, and then when you draw the text it will be drawn to that image (rather than the screen buffer). Finally unlockfocus and continue.
Matt is describing an approach where you use sprite:setImage() and either lockFocus or pushContext() to draw into that image. That's what I do most of the time. Another approach is to put your drawing calls inside the sprite:draw() function.
Here's a complete example. I tried to comment the code to explain how it all works. After launching it, press A to show the textbox. It currently draws one letter per frame; you could base it on a timer instead. I hope this helps!