Jump to content
  • Advertisement
Sign in to follow this  
  • entries
  • comments
  • views

Week of Awesome III - Initial ground work

Sign in to follow this  


So, I've set up some initial ground work for my text based game. As I mentioned previously, I'm using the ImGui library. At the time of this posting there's no support for multi-line colored text, so I had to write that myself. I went for an approach where I can just place tags within a string to colorize sections of the string, much like html tags. Took me a couple of hours, but I'm sure it'll be worth it, not only is staring at a single color really boring, it's also hard to convey some information to the player without it. Like if there's some object the player should interact with, it makes it easier if it's colored within the text.

I ran into some interesting problems when implementing this. Say you have text with tags in them that you have to parse, this text also need to be broken up into lines manually, what would you do first? Splitting the text up for the colors first leaves you with chunks that may or may not fit on a single line, having to split up these parts again seems like a lot of work. The second approach is breaking the text up by lines first, but this time you run into the problem that the tags are still there so you'll end up with lines not filling the entire width. Oh noes!

I went for the second option, but on determining where to break the lines I keep the tags in mind. That means that every time I need a length or offset into a string I manually count said length or offset and ignore tags in the process.

Another thing was that ImGui is (obviously) an immediate mode UI library, which has it's drawbacks. I would have to parse tags and break up lines on every frame, which might not be a problem for the length of my game on modern day computers, but it felt wrong to keep it like that. So I implemented some retention for my multi-line colored text, I only have to parse tags and break lines once. Okay maybe that's not exactly true... once per window resize.

That's all for now, of to some gameplay programming!

Sign in to follow this  


Recommended Comments

Using RichText enabled Unity engine for the past one year, it's easy to forget just how much trouble it is to get colored text in a any given body of text. Gratz on achieving this and having to deal with what many take for granted!

Share this comment

Link to comment

Hehe thanks, yeah it really is easy to forget, but 200 lines of code will make you remember :P.

Share this comment

Link to comment
yea, RichText is definitely a pickle to say the least. I do something similar to you, but since the text being rendered is generally passed in as a literal string, i have no immediate struct to store the different components, so i have to reparse each frame. (maybe i should support sometype of object that does this?)

anywho, looking good mussi, but not much time left!

Share this comment

Link to comment

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
  • Advertisement

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!