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 / Nested BOLD text

Author
Message
Fallout
21
Years of Service
User Offline
Joined: 1st Sep 2002
Location: Basingstoke, England
Posted: 6th Feb 2013 16:04 Edited at: 8th Feb 2013 17:34
I had to solve this problem for an app I'm working on, so thought I'd share it as it may be of use to others.

To achieve:

Hi. I'm Bob. I like swimming, pole vaulting, juggling and eating pies!

Currently you would have to create a bunch of text objects, one using a normal bitmap font and another using a bold bitmap font. You then have to position them precisely. You'd probably have lots of issues if you wanted to wrap the text by setting the max width, and generally it's a proper pain.

To solve this issue programatically you can use the extended image functionality in AppGameKit to provide a bold image and then offset the ASCII values of the bold characters in the string you want to print. This can be done by parsing the string and using a delimiter to specify what is bold and what isn't.

Here's an example:

Hi. I'm Bob. I like swimming, pole vaulting, juggling and eating pies!

Becomes:

sString = "Hi. I'm ^Bob^. I like ^swimming^, pole vaulting, ^juggling^ and eating ^pies^!"

Tell AppGameKit about your custom images, eg:



Then before you assign that string to a CreateText command or similar, parse it using this function:

sExtended = StringFunctions_Extend(sString, "^")
iNewText = CreateText(sExtended)



The final step is to correctly setup your bold subimages.txt file with the correct ASCII values. In this example I am adding 96 to the ASCII values to get a bold character from my 'extended' bitmap font graphic. So references like this:

32:1000:0:23:144
33:342:725:41:144
34:0:725:48:144
35:435:290:70:144

need to become:

128:1000:0:23:144
129:342:725:41:144
300:0:725:48:144
301:435:290:70:144


Now you can have as much normal and bold character content in your strings as you want, and only need one text object.

Hope that helps some people.

Ancient Lady
Valued Member
20
Years of Service
User Offline
Joined: 17th Mar 2004
Location: Anchorage, Alaska, USA
Posted: 6th Feb 2013 16:16
Cool! Thank you. The basic concept could be used in a lot of ways.

Cheers,
Ancient Lady
AGK Community Tester and AppGameKit Master
Fallout
21
Years of Service
User Offline
Joined: 1st Sep 2002
Location: Basingstoke, England
Posted: 6th Feb 2013 16:35
Yep, definitely, though I believe you're limited to only 1 extended image so you'll only ever get two variations on the whole character set.

Ancient Lady
Valued Member
20
Years of Service
User Offline
Joined: 17th Mar 2004
Location: Anchorage, Alaska, USA
Posted: 6th Feb 2013 17:19
Quote: "I believe you're limited to only 1 extended image"

Not quite.

There is the default font image (and extended) that is used if you don't specify a different one.

But you can load as many font image files as you want and assign them to Text objects however you desire using SetTextFontImage and SetTextFontExtendedImage.

Cheers,
Ancient Lady
AGK Community Tester and AppGameKit Master
Markus
Valued Member
20
Years of Service
User Offline
Joined: 10th Apr 2004
Location: Germany
Posted: 6th Feb 2013 18:56
nice idea

my idea because i am to lazy for writing a text parser

"Hi. I'm "+Bold("Bob")+". I like "+Bold("swimming")+", pole vaulting, "+Bold("juggling")+" and eating "+Bold("pies")+"!"

Bold is a part of your Funktion that change the Ascii Code.
Fallout
21
Years of Service
User Offline
Joined: 1st Sep 2002
Location: Basingstoke, England
Posted: 8th Feb 2013 17:39
String function above edited to fix a bug with word wrapping after space characters were ASCII shifted. Or in English, just use this one ...



Login to post a reply

Server time is: 2024-05-07 20:28:16
Your offset time is: 2024-05-07 20:28:16