βœ’οΈ The draw_text Function and Colors | myBetabox

βœ’οΈ The draw_text Function and Colors

Keyboard Guide

The draw_text Function and Setting Colors

The Code Explained

Use theΒ tab key to line up your code in the correct way (see the video to check how far right your code should start).

This function allows us to set the font and size for our in-game text.

font = pygame.font.Font(fn, size)

The text_surface function is a way for our text to ‘sit’ on the screen. Imagine having someone serve you dinner without a plate, that could get really messy!

text_surface = font.render(text, True, 255, 255, 255)

🌟 True is a Boolean value. Make sure it’s capitalized!

The 255 numbers in the code stand for (text, True, red, green, blue) colors. These colors are represented by numbers, that’s why we’re using numbers instead of color names. For the RGB values, you can use any number between 0-255.

(0, 0, 0) creates black
(255, 255, 255) creates white

Experiment with different RGB values by going to this RGB to HEX site! It allows you to input different numbers to see what color it makes. In the example below (32, 124, 212) was used to make a nifty shade of blue.

The text_rectangle function shows your text (the code below) where to go. Your server finally got a plate to put your meal on and now uses this function to find your spot at the table!

text_rect = text_surface.get_rect()

Blit is a term that means updating. If your server went to get you a drink refill, but you swapped seats with your friend, blitting lets the server know how to find you at the right spot!

surf.blit(text_surface, text_rect)