Represent Values through Images instead of Numbers

class Damage_Sprite < Sprite def initialize(targ, val) super(nil) @target = targ self.bitmap = Bitmap.new(100, 20) self.bitmap.draw_text(0,0,100,20, val, 1) self.ox = 50 self.x = @target.screen_x self.y = @target.screen_y - 40 self.z = 999 @timer = 20 end def update self.x = @target.screen_x self.y = @target.screen_y - 40 if @timer > 0 @timer -= 1 self.zoom_x += 0.01 self.zoom_y += 0.01 else self.opacity > 0 ? self.opacity -= 5 : dispose end end def dispose self.bitmap.dispose super end endIn this particular script, you can see that I am using a text to represent the damages of my actor. Is there a way and what way is it possible to represent the numbers through an indexed image?

VF1lxtV.png


For example, I want to represent it with this. How can I call two numbers? I tried calling it but failed, as it goes from an if else statement whether it is 1 to 10, 11 onwards, which is of course very unprofessional and will be long.

I need a way to represent any number with this image, but I have absolutely no idea.
Ever thought of slicing the image in 10 tiny ones, then call them each time you need a digit?

Edit:

You know...

0.png

1.png

2.png

...

9.png

Then it is simple math conditions and show a picture in a certain spot, then another next to it etc etc.

That way you can show a number like 9, a number like 125, a number like 194856 and a number like 238462893642386.

You can even use the pictures in more places than this script I suppose. 😉

P.S.

I don't know if there is a crop method to do the same, but I would also prefer my suggestion, since it doesn't request that extra CPU power to be done. 😉
If you look through some of the sprite methods you can see how they get cropped.

so it would be something like:

self.bitmap = some bitmapvalue = some numberw = self.bitmap.width / total columnsh = self.bitmap.heightx = value * wself.src_rect.set(x, 0, w, h)That's the case for splitting images in just columns and having a single row.  For rows and columns its the same idea but just different math.

edit. oh for like 2+ characters / digits, I would just suggest that where ever you're calling this from, make the sprite for each value.  Something like:
 

Code:
value = integerspacing = 24i = 0value.to_s.each_char do |n|  sprite = Number_Sprite.new(n)  sprite.x = i * spacing   i += 1end
Thanks a lot Quasi, I will be looking at such way and I will contact you if some problems arise.

Original thread: https://forums.rpgmakerweb.com/threads/represent-values-through-images-instead-of-numbers.37272/