I am rendering some text from the surface, but it seems the text surface is filled with a color.
the white blocks and green block is text surface rendered to the main surface by the code below
import pygame.freetype as ft
font_dir = "./fonts/D2Coding.ttf"
font = ft.Font(font_dir, 24) # Font('fonts\D2Coding.ttf')
content = "some texts"
font_color = (255,255,255)
font_surf_rect = font.render(content, True, font_color) # (<Surface(34x18x32 SW)>, <rect(1, 18, 34, 18)>)
main_screen.blit(*font_surf_rect)
is there any method to make the text_surface background transparent, while keeping my text fully opaque?
- EDIT (resolved)
I have used this font object well with the font.render_to
function, and I am now on pygame 2.1.2
I just wanted to render my text to a given position as the center, so I just changed my code to use font.render_to
and its position from font.render()[0].get_rect(center=given_position)
font_surf, font_rect = font_surf_rect
if center: rect = font_surf.get_rect(center=pos)
else: rect = font_surf.get_rect(topleft=pos)
font.render_to(main_screen, rect[:2], text, font_color, size=font_size)
and this worked just fine.