So I thought it would be nice to create some retro fonts using the sprites, and manage to create a reasonable character set. Problem is I can't seem to find a way to parse the text to display the proper characters.
In another language, I'd parse the string using something like MID$ then perhaps use a batch of conditional IF statements to match the character and display the correct sprite.
I've dug through the WIKI manual and just don't see enough controls to do the job.
Can someone help?
Here's the current code...
-- fonts by shadowbyte cls() x=0 spacing=8 mytext="hello" print" " print" " print"should say hello" for j = 1,(#mytext) do spr(j,x,y) x+=spacing end |
I think you're gonna have to analyse each character and select the right sprite number accordingly.
For example, you could use the Sub() function to get the character at point J in mytext inside your for loop. Then have some kind of lookup table that links letters (a-z) to sprite indexes (1-16).
See the Pico-8 manual for API reference on how to use Sub and other functions.
That's command I was hunting for! Thank you.
So far not an elegant solution, but it's working.
-- fonts 0.2 by shadowbyte cls() x=0 spacing=8 mytext="shadowbyte" print" " print" " for j = 1,(#mytext) do letter=(sub(mytext,j,j)) if letter =="a" then alpha=0 end if letter =="b" then alpha=1 end if letter =="c" then alpha=2 end if letter =="d" then alpha=3 end if letter =="e" then alpha=4 end if letter =="f" then alpha=5 end if letter =="g" then alpha=6 end if letter =="h" then alpha=7 end if letter =="i" then alpha=8 end if letter =="j" then alpha=9 end if letter =="k" then alpha=10 end if letter =="l" then alpha=11 end if letter =="m" then alpha=12 end if letter =="n" then alpha=13 end if letter =="o" then alpha=14 end if letter =="p" then alpha=15 end if letter =="q" then alpha=16 end if letter =="r" then alpha=17 end if letter =="s" then alpha=18 end if letter =="t" then alpha=19 end if letter =="u" then alpha=20 end if letter =="v" then alpha=21 end if letter =="w" then alpha=22 end if letter =="x" then alpha=23 end if letter =="y" then alpha=24 end if letter =="z" then alpha=25 end spr(alpha,x,y) x+=spacing end |
try something like this:
def="abcdefghijklmnopqrstuvwxyz" lut={} for i=1,#def do lut[sub(def,i,i)]=i-1 end ... alpha=lut[letter] |
Thank you ultrabrite.
I've posted an update to the code which includes the refinements. It'll take me a bit to fully digest the nature of how the code works.
Re-titled thread. Thanks for the assist. It is time to start working on a game.
cool cool :)
i like these kind of small exemple, perfect to start learning
thanks
[Please log in to post a comment]