RPG Maker XP-VXA Bitmap Number

Version 1.4

This is a very basic script I wrote a while back for VX, then recently dug up and rescued for use in my XP projects. ... and then later on I used it again for VXAce. It's a pretty flexible script. A thing that has always bothered me is coming across a nice font, only to find that the kerning for numbers is inconsistent - seeing things like the play-time or similar jump about when a 1 appears, or worse, other numbers too.

This script allows you to use an image for numbers wherever you please. This isn't plug-and-play. If you want to see your image, you'll have to add the code where necessary.

Sample Bitmap

Huh? Oh fine here you go:

Use

The defaults can be changed by editing the definition in the code. It's really not that big a script, so it shouldn't be hard.

Script

The code below is formatted for VX/Ace. To use in XP, replace Cache.system with RPG::Cache.windowskin, or whichever line you need to use for wherever you have your number image.

#==============================================================================
# ■ Bitmap
#==============================================================================

class Bitmap
  #--------------------------------------------------------------------------
  # ● Draw Bitmap Number
  #--------------------------------------------------------------------------
  def draw_bitmap_number(value, x, y, align = 0, skin = "numbers/nwh", offset = 2)
    # Get image
    numerals = Cache.system(skin) # for XP: numerals = RPG::Cache.windowskin(skin)
    digit = (numerals.width / 10)
    text = value.to_s
    value = value.to_i if value.is_a?(String)
    char = 0
    # Get number size
    tx = ((digit-offset) * text.length) + offset
    # Offset x
    case align
    when 1
      x -= (tx / 2)
    when 2
      x -= tx
    end
    while ((c = text.slice!(/./)) != nil)
      n = digit * c.to_i
      src = Rect.new(n, 0, digit, numerals.height)
      self.blt(x + char, y, numerals, src)
      char += digit - offset
    end
  end
end

Credit

Credits should go to myself, Taylor.

Advanced Notes

This script should work fine with numbers that have leading zeros, like playtime.

hour = sprintf("%02d", time / 60 / 60)
min = sprintf("%02d", time / 60 % 60)
sec = sprintf("%02d", time % 60)
contents.draw_bitmap_number(sec, x + 162, y, 2)
contents.draw_bitmap_number(min, x + 132, y, 2)
contents.draw_bitmap_number(hour,x + 102, y, 2)

Tuesday, 4th February 02015