TIC-80 icon indicating copy to clipboard operation
TIC-80 copied to clipboard

Enhancement: Font Colour

Open BuoYancYdabl opened this issue 3 years ago • 8 comments

Why this should be added Currently now it is possible to change font's colour by poking it or manually.

How this might be implemented Adding one more parameter [colour=-1]. When this parameter is 0-15 it makes 0 colour transparent and replaces empty ones with needed colour. So how is this possible? First of, check colour parameter, do replacement, then check for colourkey to make invisible borders. Using colour 0 will lead to fully transparent font, should work same as vbank().

BuoYancYdabl avatar Jul 21 '22 23:07 BuoYancYdabl

I'm not sure I follow what is being asked for here or what API method is requesting be changed. Source example or before/after mockups might help illustrate the idea.

joshgoebel avatar Dec 05 '22 01:12 joshgoebel

I think he suggests to add a "colour" parameter to the font() function. https://github.com/nesbox/TIC-80/wiki/font

Skeptim avatar Feb 08 '23 22:02 Skeptim

This function will draw text to the screen using the foreground spritesheet as the font.

Except the font is already potentially 16 colors... because each letter if a full sprite. Someone could do this easily with a wrapper that updates the palette mapper to map all 15 (not black?) colors to a single specified color if someone is just using the font as a glorified 1-bit font.

joshgoebel avatar Feb 09 '23 00:02 joshgoebel

Except the font is already potentially 16 colors... because each letter if a full sprite. Someone could do this easily with a wrapper that updates the palette mapper to map all 15 (not black?) colors to a single specified color if someone is just using the font as a glorified 1-bit font.

Today I was like "Okay, this time I will understand that "easy" stuff so that I can add an example to the font wikipage on how to change the color using font and I will finally use it in my translation tools cart!! I can do it!" XD That was on my "To do" list since you wrote it, but… no, not anyone could do this "easily", haha ^^ Honestly I think I understood the principle but I guess you need to use peek and poke and that is black magic to me! The wiki is cryptic to me on how to use them.

So, could you give an example of what you say? Like a colored_font(text,x,y,color) function?

Skeptim avatar Apr 11 '24 19:04 Skeptim

@Skeptim it's the same thing as changing colors for any sprite, like:

poke4(0x3FF0*2+1,15) -- swaps the color 1 for 15
font(...)
poke4(0x3FF0*2+1,1) -- change it back

Weeppiko avatar Apr 26 '24 19:04 Weeppiko

Great! Thanks a lot @Weeppiko!

Skeptim avatar Apr 26 '24 19:04 Skeptim

@Weeppiko Mmh… in fact the swap back does not work and I don't know how to make it work.

Here is what I do

initial_color=12
new_color=7
poke4(0x3FF0*2+initial_color,new_color)
font("Hello font!", 84, 84)
poke4(0x3FF0*2+new_color,initial_color)
font("Hello font!", 84, 104)

and I get twice the same color for my "Hello font!" text

video18

Edit: I also tested poke4(0x3FF0*2+initial_color,new_color) and poke4(0x3FF0*2+new_color,new_color)

Skeptim avatar May 08 '24 16:05 Skeptim

@Skeptim You should do: poke4(0x7FE0+initial_color,initial_color) to return it back. What you did wrong is first you made color 12 into color 7, and then you made color 7 into color 12. You swapped their places. But the sprites still use color 12. To return it to normal, you need to make color 12 into color 12. Think of it as indexes into color tables (which it in fact is). So, you have a table of colors (y), and palette indexes (x), and the palette is just a mapping y=f(x). Your sprites use x=12. And the palette says "index x=12 points to color y=12". By running: poke4(0x7FE0+initial_color,new_color) You say "index x=12 now points to color y=7". This makes your font change color. To change it back, you run: poke4(0x7FE0+initial_color,initial_color) Which makes the mapping say "index x=12 now point to color y=12". By the way, I recommend using 0x7FE0 instead of 0x3FF0*2, it takes 2 less bytes and gets rid of a multiplication (I'm not sure if lua or other languages do constant evaluation only once or every time the line executes, but just in case).

S0ZDATEL avatar Jul 30 '24 10:07 S0ZDATEL