How to put a text on pygame screen?
I was trying to put a text inside a pygame screen at a specific coordinate, what can I do to print a text and restrict its area?
import sys, pygame
pygame.init()
size = width, height = 800, 600
speed = [0, 0]
black = 0, 0, 0
screen = pygame.display.set_mode(size)
fundo = pygame.image.load("baner.jpg")
dialogo = pygame.image.load("dialogo.png")
estatico = fundo.get_rect()
while 1:
for event in pygame.event.get():
if event.type == pygame.QUIT: sys.exit()
estatico = estatico.move(speed)
if estatico.left < 0 or estatico.right > width:
speed[0] = -speed[0]
if estatico.top < 0 or estatico.bottom > height:
speed[1] = -speed[1]
screen.fill(black)
screen.blit(fundo, estatico)
screen.blit(dialogo, estatico)
pygame.display.flip()
This is what I have so far, two images and wanted to put a text on top of the dialog
0
Author: Hugo Amorim, 2019-09-13
1 answers
from pygame import font
txt='hello world' ##### armazena o texto
pygame.font.init() ##### inicia font
fonte=pygame.font.get_default_font() ##### carrega com a fonte padrão
fontesys=pygame.font.SysFont(fonte, 60) ##### usa a fonte padrão
txttela = fontesys.render(txt, 1, (255,255,255)) ##### renderiza o texto na cor desejada
screen.blit(txttela,(50,900) ##### coloca na posição 50,900 (tela FHD)
pygame.display.update() ##### CARREGA A TELA E EXIBE
-1
Author: RODINEY TAKARA, 2020-02-26 00:32:48