Log In  

Cart #26232 | 2016-07-31 | Code ▽ | Embed ▽ | License: CC4-BY-NC-SA

P#26219 2016-07-31 12:57 ( Edited 2016-08-02 12:29)

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?

P#26220 2016-07-31 12:59 ( Edited 2016-07-31 16:59)

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
P#26221 2016-07-31 13:17 ( Edited 2016-07-31 17:17)

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.

P#26222 2016-07-31 13:35 ( Edited 2016-07-31 17:35)

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
P#26223 2016-07-31 13:47 ( Edited 2016-07-31 17:47)

try something like this:

def="abcdefghijklmnopqrstuvwxyz"
lut={}
for i=1,#def do lut[sub(def,i,i)]=i-1 end

...

alpha=lut[letter]
P#26227 2016-07-31 15:56 ( Edited 2016-07-31 19:56)

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.

P#26238 2016-07-31 19:03 ( Edited 2016-07-31 23:03)

Re-titled thread. Thanks for the assist. It is time to start working on a game.

P#26263 2016-08-01 10:18 ( Edited 2016-08-01 14:18)
:: s199

cool cool :)
i like these kind of small exemple, perfect to start learning
thanks

P#26313 2016-08-02 08:29 ( Edited 2016-08-02 12:29)

[Please log in to post a comment]

Follow Lexaloffle:        
Generated 2020-07-07 03:18 | 0.019s | 4194k | Q:37