Envision, Create, Share

Welcome to HBGames, a leading amateur game development forum and Discord server. All are welcome, and amongst our ranks you will find experts in their field from all aspects of video game design and development.

Bitmap fonts in place of fonts.

Okay, so i found this script here viewtopic.php?f=11&p=807905 , i think it might be what i'm looking for.. BUT.. their are image files missing he has to help demonstrate how to use the script, and ofcourse, their are no demos to be found, is anyone using this script or do they know of a better script for replacing fonts with actual bitmap(PNG) images?
And if no one can help me with this, does anyone know anything better?
 

mawk

Sponsor

Looking at this:

# This is a comment
# Each line has four fields.
# The first field specifies the character to
# draw. (If the character includes a space or is
# any one of: # , " then the character must be
# in quotation marks. To specify a quotation mark,
# put a backslash before it, like this: "\"" )
# It must be a single character, as multiple
# characters at once are not supported.
# The second field specifies the X coordinate of the
# beginning of the character in the bitmap font.
# The third field specifies the X coordinate of the
# character's starting point. This is normally set
# to field 2, but can be made
# slightly larger if the character hangs to the left
# of the previous character (e.g., cursive f, j),
# in order to tighten the spacing comfortably.
# The fourth field specifies the width of the character
# in the bitmap font.
#
# First character is A, located 0 pixels from the image
# and with a width of 18
A,0,0,18
# The next character is B, located 18 pixels from
# the beginning of the image and with a width of 17
B,18,18,17
C,35,35,15
D,50,50,17
E,67,67,15
F,82,82,13
# The fifth field, which is optional, specifies the X
# coordinate of where this character ends and the next
# character begins, relative to the beginning of the bitmap
# font image. If not specified, this field is equal
# to the sum of fields 1 and 3.
# Space glyph (notice the quotes)
" ",0,0,0,6

It seems like the image you'd be using would be all the symbols you need in a long row, like this:

samppppp1.png


With the list of letters being:
A,0,0,14
B,14,14,14
C,28,28,14
And so on for each one. The first letter is the symbol it's supposed to represent, the second is its distance from the left edge of the image, the third is where the character actually begins (unimportant, except to fix the kerning of a letter if it's a little off when you test it), and the fourth is the character's width -- the letters in the above sample are all 14 pixels wide, but you'll need to do some testing on your own when you make your own sheet of characters.

It looks like it's all there in that spoiler I quoted from the script's topic, but is there anything in particular you're still wondering about?
 
Does it work a bit like SFonts?
I was using SFonts.. made one long font to use already.. but when i started to .. um.. use them.. the game just wanted to do these long pauses...
So this script sounded more promising, but i'm not exactly sure what i'm doing, even by reading that explanation, i'm still a bit lost...
Maybe if i just sit here and read it over and over again.. and.. try and figure it out.. let it soak into my brain a bit...
I think i get it though, but when the images were missing.. i felt a bit lost.
I will just kinda, work with it i suppose until i figure it out.
 

mawk

Sponsor

I've never worked with SFonts, so I couldn't say, but messing around with it on your own for a while sounds like a good idea. If you wind up stumped with anything, though, don't hesitate to ask.
 

Atoa

Member

@Mikepjr
The problem with sfont is when you and the "self.contents.sfont = SFont.new("Font")" on an update method.
This will make it loads the sfont and it's bitmaps every frame. Load an big graphic 40 times in an second won't make any good for the FPS XD

Instead you could do this: on the Main, bellow the 'begin' add this code:
$sfont = [SFont.new("Font 1"), SFont.new("Font 2"), SFont.new("Font 3")]
You can add how many sfonts you want.
then, when going to call the script use: self.contents.sfont = $sfont[INDEX]
the INDEX, are the font index on the array.
self.contents.sfont = $sfont[0] will use the "Font 1", self.contents.sfont = $sfont[1] will use the "Font 2", and so.
 

Thank you for viewing

HBGames is a leading amateur video game development forum and Discord server open to all ability levels. Feel free to have a nosey around!

Discord

Join our growing and active Discord server to discuss all aspects of game making in a relaxed environment. Join Us

Content

  • Our Games
  • Games in Development
  • Emoji by Twemoji.
    Top