This project is read-only.

Press (A) to jump

Apr 5, 2009 at 7:54 PM
Edited Apr 5, 2009 at 7:56 PM
I have a question about displaying text with Xen.
To display "Hello World" in a TextElement or in a TextElementRect looks easy enough.
But how could I print "Press (A) to jump"? Of course "(A)" would be the green A button and not text. If I draw that string in red, I don't want to see the A button brown, so I can't just insert the button images inside the texture of the SpriteFont and make buttons special characters for each font I use in the game.

So how would you solve that? internally create two text object, one for the text, the other for the buttons, with lots of blank space where the text/button on the other text object would be displayed?

Congrats about Xen and good luck with your job.
Apr 6, 2009 at 12:15 PM

This isn't something I've considered, but it's certainly a valid thing to do...

What I'd suggest for the moment, is render the text with two text elements. The first block, and the second block ("Press " and " to jump").
Offset the second block based on the size returned by SpriteFont.MeasureString(). (Note however that the sprite code in xen is slightly different to XNA text sprites (for instance, tab characters are accounted for) so the values may differ slightly).

Then simply use a TexturedElement for the 'A' image that sits in between the two...

Does that make sense?
And thanks for the encouragement :-) I'll have some down time soon while moving, so I'll be able to get some work done and hopefully the next version out (which will be minor compared to 1.5).

Apr 6, 2009 at 11:02 PM
yes that would work great for simple stuff like my previous exemple, but in case there is something more complex, lots of text and buttons with word wrap, like a tutorial text that explains the controls. Cutting everything into multiple textelement and texturedelement. Also if I care about localization... I already have nightmares
Apr 7, 2009 at 1:06 AM
That's a very valid point. I'll have a think and see if these is anything that can be done to make this easier.
Apr 15, 2009 at 6:52 AM
Hi., I've just uploaded the most recent bug fix update, and I squeezed in a new feature in the text classes. You can now add 'Inline' elements that sit at specified character indices. These should be useful for having the A button graphic, etc.
The text tutorial (15) has been updated with a really simple example.
Let me know how things go.