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.
Making tiny-font strings using sprite slices?
Moderators: marionline, SDHawk
- Bob the Hamster
- Lord of the Slimes
- Posts: 7658
- Joined: Tue Oct 16, 2007 2:34 pm
- Location: Hamster Republic (Ontario Enclave)
- Contact:
- Bob the Hamster
- Lord of the Slimes
- Posts: 7658
- Joined: Tue Oct 16, 2007 2:34 pm
- Location: Hamster Republic (Ontario Enclave)
- Contact:
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">
You would use it like this:
And then you could position that slice however you want.
You can update the number like this:
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.
<img src="https://i.imgur.com/14Nuahg.png">
Code: Select all
define constant(1, tiny number box border sprite set)
define constant(8, tiny number font height)
define constant(6, tiny number font width)
script, create tiny number slice, number, begin
variable(sl)
sl := create container(0, tiny number font height)
change tiny number slice(sl, number)
exit returning(sl)
end
script, change tiny number slice, sl, number, begin
variable(is negative)
if(number < 0) then(
is negative := true
number := abs(number)
)
free slice children(sl)
set slice width(sl, 0)
while(number) do(
add tiny digit(sl, (number ,mod, 10))
number := number / 10
)
if(is negative) then(
# Frame number 10 is the - symbol
add tiny digit(sl, 10)
)
end
script, add tiny digit, sl, fr, begin
# Adds the new digit on the left
variable(digit)
digit := load border sprite(tiny number box border sprite set)
set parent(digit, sl)
set sprite frame(digit, fr)
realign slice(digit, edge:right, edge:center, edge:right, edge:center)
set slice x(digit, slice width(sl) * -1 + (16 -- tiny number font width))
set slice width(sl, slice width(sl) + tiny number font width)
end
You would use it like this:
Code: Select all
myhandle := create tiny number slice(12345)
You can update the number like this:
Code: Select all
change tiny number slice(myhandle, 6789)
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(col, sl)
col := load slice collection(5)
sl := lookup slice(sli:max hp container, col)
change tiny number slice(sl, max hp)
Last edited by Bob the Hamster on Thu Jun 25, 2015 2:58 pm, edited 1 time in total.