Making tiny-font strings using sprite slices?

Ask and answer questions about making games and related topics. Unrelated topics go in that other forum.

Moderators: marionline, SDHawk

Post Reply
User avatar
Foxley
Metal Slime
Posts: 832
Joined: Sat Nov 09, 2013 5:54 pm

Making tiny-font strings using sprite slices?

Post by Foxley »

I'd like to be able to display numbers but the 8x8 character font takes up too much space in the hero character's box in the HUD. So I was thinking of making tiny sprites of numbers - walkabouts or box edges (which I don't use in Hollowkeep) - and finding a way to string them together so they're placed close together. But, the challenge would be being able to manipulate these sprites, having them represent numerical values which are used in strings.

For instance, let's say "$30=get hero current stat (stat:HP)" and the hero's current health is 63 and wanting to display a tiny 6 sprite and a tiny 3 sprite. Then having a script to refresh those sprite slices to get the updated string value.

Any ideas on an approach to take with this? I'd of course just like to make a tiny set of numbers in the regular font, but the problem would be using them as numbers when writing scripts, calculating damage and other numbers stuff.
User avatar
Bob the Hamster
Lord of the Slimes
Posts: 7658
Joined: Tue Oct 16, 2007 2:34 pm
Location: Hamster Republic (Ontario Enclave)
Contact:

Post by Bob the Hamster »

I have a script for this, I'm on my phone right now, but I'll try to post it tomorrow. I used it for the damage numbers in Vorpal Florist and Paladin Traducer.
User avatar
Foxley
Metal Slime
Posts: 832
Joined: Sat Nov 09, 2013 5:54 pm

Post by Foxley »

Awesome, thank you.
User avatar
Bob the Hamster
Lord of the Slimes
Posts: 7658
Joined: Tue Oct 16, 2007 2:34 pm
Location: Hamster Republic (Ontario Enclave)
Contact:

Post by Bob the Hamster »

Here is the script. This is a slightly cleaned-up version of the one I use in Paladin Traducer. It is intended for this 6x8 font, but it could easily be adapted for something smaller (or bigger!).

<img src="https://i.imgur.com/14Nuahg.png">

Code: Select all

define constant&#40;1, tiny number box border sprite set&#41;
define constant&#40;8, tiny number font height&#41;
define constant&#40;6, tiny number font width&#41;

script, create tiny number slice, number, begin
  variable&#40;sl&#41;
  sl &#58;= create container&#40;0, tiny number font height&#41;
  change tiny number slice&#40;sl, number&#41;
  exit returning&#40;sl&#41;
end

script, change tiny number slice, sl, number, begin
  variable&#40;is negative&#41;
  if&#40;number < 0&#41; then&#40;
    is negative &#58;= true
    number &#58;= abs&#40;number&#41;
  &#41;
  free slice children&#40;sl&#41;
  set slice width&#40;sl, 0&#41;
  while&#40;number&#41; do&#40;
    add tiny digit&#40;sl, &#40;number ,mod, 10&#41;&#41;
    number &#58;= number / 10
  &#41;
  if&#40;is negative&#41; then&#40;
    # Frame number 10 is the - symbol
    add tiny digit&#40;sl, 10&#41;
  &#41;
end

script, add tiny digit, sl, fr, begin
  # Adds the new digit on the left
  variable&#40;digit&#41;
  digit &#58;= load border sprite&#40;tiny number box border sprite set&#41;
  set parent&#40;digit, sl&#41;
  set sprite frame&#40;digit, fr&#41;
  realign slice&#40;digit, edge&#58;right, edge&#58;center, edge&#58;right, edge&#58;center&#41;
  set slice x&#40;digit, slice width&#40;sl&#41; * -1 + &#40;16 -- tiny number font width&#41;&#41;
  set slice width&#40;sl, slice width&#40;sl&#41; + tiny number font width&#41;
end

You would use it like this:

Code: Select all

myhandle &#58;= create tiny number slice&#40;12345&#41;
And then you could position that slice however you want.

You can update the number like this:

Code: Select all

change tiny number slice&#40;myhandle, 6789&#41;
The width of the slice will be automatically updated.

The tiny number slice is really just a container slice with a bunch of sprite slices inside, so you can actually use any old container, it does not have to be one created with "create tiny number slice"

For example, you could pre-position a container in a slice collection, and then use "change tiny number slice" to insert digits into it.

Code: Select all

variable&#40;col, sl&#41;
col &#58;= load slice collection&#40;5&#41;
sl &#58;= lookup slice&#40;sli&#58;max hp container, col&#41;
change tiny number slice&#40;sl, max hp&#41;
Last edited by Bob the Hamster on Thu Jun 25, 2015 2:58 pm, edited 1 time in total.
Post Reply