Sorry your browser is not supported!

You are using an outdated browser that does not support modern web technologies, in order to use this site please update to a new browser.

Browsers supported include Chrome, FireFox, Safari, Opera, Internet Explorer 10+ or Microsoft Edge.

AppGameKit Classic Chat / Is rolling your own text solution theonly way to perfect text alignment in AGK2?

Author
Message
MikeHart
AGK Bronze Backer
20
Years of Service
User Offline
Joined: 9th Jun 2003
Location:
Posted: 13th Dec 2014 23:11
Hi folks,

creating some kind of text adventure is on my bucket list. So far I think I need to create my own text rendering solution that supports kerning and offsets properly to do this, i think.

Or did I miss something when I studied the docs?

Cheers
Michael
29 games
18
Years of Service
User Offline
Joined: 23rd Nov 2005
Location: not entirely sure
Posted: 13th Dec 2014 23:54
I never knew the kerning was a thing.

To answer your questions, no there are no inbuilt commands as far as far as I understand them, so you'll have code it yourself.

I'm not sure how you'd go about doing this so I can't be more helpful.

However, if it was me, and I'd like to do a text based game so it might be me, I'd just design a font that looked right and without too much faffing about.

Funnell7
12
Years of Service
User Offline
Joined: 8th Sep 2011
Location: UK, England
Posted: 14th Dec 2014 00:05
Isn't kerning just basically overlapping the letters slightly? If so a negative value with SetTextSpacing would achieve this, no?
29 games
18
Years of Service
User Offline
Joined: 23rd Nov 2005
Location: not entirely sure
Posted: 14th Dec 2014 00:35
According to Wikipedia the amount of overlapping depends on the characters that are adjacent to each other, the font being used and the case (upper or lower). For instance for the word "WAR" the would be overlap between the W and the A but not for A and R. It's all about getting words on the page to look pleasing to the eye, not just about getting the spacing correct.

The SetTextSpacing()command spaces all the letters by the same amount so wouldn't adjust the overlap to suit the different characters.

Yes, my Saturday nights have now got to the point where I'm studying the shape of letters to see how they overlap. I'm going to call it a win, to do anything is just going to mess with my self-esteem.

=PRoF=
21
Years of Service
User Offline
Joined: 17th Mar 2003
Location: Milton Keynes, UK
Posted: 14th Dec 2014 01:08
All you need to do is edit the values in the text file which accompanies a bitmap font image. These specify where on the atlas image the letters are grabbed from, this allows you to edit the exact width of each letter.

29 games
18
Years of Service
User Offline
Joined: 23rd Nov 2005
Location: not entirely sure
Posted: 14th Dec 2014 01:25
But the issue isn't to do with individual characters or even the width of each character. It's to do with pairs of characters, their shape and their relative position, so for example the overlap between W and A is different from M and A. The width of W and M are probably the same but the A is positioned differently depending on whether it's preceded by a W or an M.

Also, I don't think setting the coordinates where the subimage "grabs" the character from the bitmap font would actually generate any overlapping of the characters.

Or am I missing something?

=PRoF=
21
Years of Service
User Offline
Joined: 17th Mar 2003
Location: Milton Keynes, UK
Posted: 14th Dec 2014 02:02
Hmm, you're possibly right. Sorry.

xGEKKOx
AGK Master
15
Years of Service
User Offline
Joined: 7th Dec 2008
Location: Italy
Posted: 14th Dec 2014 05:05
You can also use GetTextLenght to calculate padding and doing your personal function like mine in c++ in the Gekko Manager.
I use many times the scroller for news, and i use this trick to get the end of the text.

JimHawkins
14
Years of Service
User Offline
Joined: 26th Jul 2009
Location: Hull - UK
Posted: 14th Dec 2014 10:02
To do proper kerning is a little complicated. You need a table of "pairs" including the information about how far the second character should be shifted to the left. If you want to render at different font sizes this gets complicated.

I would have an array of some type containing: a sprite with the glyph and its extent to the right. I would then scan the string to be displayed in pairs, comparing to a kerning table, and build up the text image character by character.

The word AWAY demonstrated this: there are three pairs - AW - WA - AY and so there will a negative index for the right hand letter in each pair.

In a text adventure there will be a lot of repeated words and phrases, so these could be pre-rendered to images, hence saving a lot of time during program run.

-- Jim - When is there going to be a release?
MikeHart
AGK Bronze Backer
20
Years of Service
User Offline
Joined: 9th Jun 2003
Location:
Posted: 14th Dec 2014 10:57
Thanks for all the input.

It's not only about Kerning, but also about the Y offset of lowercase characters. AGK2 scales them up to the size of uppercase characters which looks then horrible. But I did my own solution in a different tool before so I know what I need. Hopefully the performance won't be that bad with AGK2 Tier1.
Nelvin
9
Years of Service
User Offline
Joined: 23rd Nov 2014
Location:
Posted: 14th Dec 2014 11:21 Edited at: 14th Dec 2014 11:24
I'd say, go for the primary game functionality first.

Of course I have seen games (even commercial ones) with really horrible kerning, sometimes it's even hard to notice whether it's a space separating 2 words or a wide gap between two glyphs

The most simple solution is to just use a font that works reasonable well without additional defined kerning pairs for all kinds of character combinations.

If, at some point, you do have your game running and your content defined and you're not happy with the quality of the rendered text, implement a better one. It's not that hard, all you need is a table with x offsets for each glyph in a defined scale so you can adjust it for your used font size.

Haven't done much with AppGameKit, but a quick test with just the default font with mixed case characters works as expected.
MikeHart
AGK Bronze Backer
20
Years of Service
User Offline
Joined: 9th Jun 2003
Location:
Posted: 14th Dec 2014 12:25
The default font works with mixed cases. But if you use an external tool which creates an atlas and each character has a different size, then AppGameKit scales smaller characters.
JimHawkins
14
Years of Service
User Offline
Joined: 26th Jul 2009
Location: Hull - UK
Posted: 14th Dec 2014 12:33
for this purpose it's simpler to create glyphs that take ascenders and descenders into account.

But I agree with Nelvin that getting the engine working first is a good idea!

-- Jim - When is there going to be a release?
paulrobson
9
Years of Service
User Offline
Joined: 22nd Nov 2014
Location: Norfolk, England
Posted: 17th Dec 2014 19:32
Kerning doesn't really matter, 99% of cases it is used for titles/scores etc.

Login to post a reply

Server time is: 2024-04-25 17:56:10
Your offset time is: 2024-04-25 17:56:10