Retro Gadgets

Retro Gadgets

Not enough ratings
How to use the Built In Font (and draw it to a screen)
By 반딧불 세레
Quick guide how to use the Built-In font and draw it to a screen (because the dev documentation is slightly wrong)
   
Award
Favorite
Favorited
Unfavorite
How To
In the developer provided documentation, it shows an incorrect way of calling the built in font. This is how it's actually done.
In the pictures I've highlighted the code that we'll be using. Please disregard the rest of it as it's part of a project I'm working on. (feel free to use it if you want to though!)
------------------------------------------------------------------------------------------------------------------------------------
If you just want the built in font:
local fontBasic = gdt.ROM.System.SpriteSheets["StandardFont']
------------------------------------------------------------------------------------------------------------------------------------

You'll need a video chip assigned to the screen if you wish to draw to the screen. You'll also need a ROM chip installed.

NOTE: Steps 1 and 2 will need to be placed ABOVE the update function. Step 3 will need to be placed INSIDE the update function (or whatever function you're using for the screen)
Step 1:
Code:
local vid = gdt.VideoChip0

"vid" can be named whatever you want. If you have more than one Video Chip you'll need to make sure it's the right one.

Step 2:
Code:
local fontBasic = gdt.ROM.System.SpriteSheets["StandardFont']

The "fontBasic" can be named whatever you want it to be.


Now, to draw it to a screen you simply do this (highlighted section)


Step 3:
Code:
vid.DrawText(vid, vec2(0,0),fontBasic,"volume",color.red,color.blue)

So first we call the Video Chip with vid. (or whatever you named it in Step 1). Then DrawText is the command to, well, draw text onto the screen.

Inside the parentheses() you call the Video Chip with vid (or whatever you named it in Step 1).

Then we choose where on the screen it will go with vec2(0,0). The numbers are X and Y co-ordinates. Since I want it in the top left, I simply put 0,0.

Next we call the font of the text that we want. We'll just use the built in font by calling fontBasic (or whatever you named it in Step 2).

Then we type out what we want to be displayed in " "
For this example I just want it to say "volume" on the screen.

Then we choose the color of the font, and lastly the color of the background.

If your text is something that will update (a volume number for example) you'll want to make sure that it clears the old text before writing new text. Otherwise it will keep drawing over top of itself.
This is simply done with:


Code:
vid.Clear(vid,color.blue)

vid - Once again calling the Video Chip.
.Clear - Clears the text.
(vid,color.blue) - Calling the Video Chip (no idea why this has to be done twice) then a background color.


Now when we power it on we can see the red "volume" text being displayed in the top left of the screen with a blue background.

I have zero coding experience but my brother was able to guide me through these steps. If I can do it then anyone can!
I've tried to explain this as simply as possible but it probably looks like word salad. Leave me a comment if something is unclear.
Hope this helps :)
6 Comments
Invention64 25 Sep, 2023 @ 8:19am 
As mentioned earlier you can use : instead of . in Lua to pass the table you are calling in as the first argument. This allows you to write code as if you were using classes, while still keeping Lua functional.
Veronicap 6 Dec, 2022 @ 7:23pm 
Nice easy guide; thanks. But it does miss one thing: you have to assign the video chip to the screen. gdt.Screen0.VideoChip = *name of video chip*
littlemanjoes 6 Dec, 2022 @ 9:50am 
blank you are correct
Blank 6 Dec, 2022 @ 1:58am 
i have found that if you use : between a component like vid and a command like clear (vid:clear) you dont need to state vid again in the parenthesis, im not sure if that messes with things.
Mitch 5 Dec, 2022 @ 3:18am 
nice
반딧불 세레  [author] 5 Dec, 2022 @ 12:08am 
Ok when I say call I mean passing a parameter, but you get the idea XD