Skip to main content
GameDev.net gamedev.net

PRO Tired of ads? Read GameDev.net ad-free and help keep the community independent with GameDev Pro — $3/month.

Week of Awesome III - Initial ground work

Week of Awesome III - Initial ground work

Mussi
Mussi
Journal of Mussi · · 2 min read
3,708 3
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!

Screenshot:

Discussion

Loading comments...