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:
iImgFont = loadImage("font/Lato.png")
SetTextDefaultFontImage(iImgFont)
iImgFontBold = loadimage("font/Lato-Bold.png")
SetTextDefaultExtendedFontImage(iImgFontBold)
Then before you assign that string to a CreateText command or similar, parse it using this function:
sExtended = StringFunctions_Extend(sString, "^")
iNewText = CreateText(sExtended)
#constant C_STRINGFUNCTIONS_ASC_SHIFT = 96
function StringFunctions_Extend(sText as string, sDelimit as string)
sFinal as string
sToken as string
sChar as string
iTokens as integer
iExtend as integer
iTokens = CountStringTokens(sText,sDelimit)
iExtend = 0
sFinal = ""
if mid(sText,1,1) = sDelimit then iExtend = 1
for t = 1 to iTokens
sToken = GetStringToken(sText,sDelimit,t)
if iExtend = 0
sFinal = sFinal + sToken
iExtend = 1
else
for c = 1 to len(sToken)
sChar = mid(sToken,c,1)
if sChar = " "
sFinal = sFinal + " "
else
sFinal = sFinal + chr(asc(sChar)+C_STRINGFUNCTIONS_ASC_SHIFT)
endif
next c
iExtend = 0
endif
next t
endfunction sFinal
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.