我该如何解决这个问题?
我看不到背景图像上方的文本,如何创建出现在背景图像顶部的表面?
我正在尝试为我的游戏制作按钮,因此我需要在首页上添加越来越多的文本,但没有任何方法可以使文本出现在图像上方,并且尽管“翻转”,但它还是在没有文本的情况下弹出代码中存在函数和更新函数。
#Err0r AttributeError: type object 'pygame.surface.Surface' has no attribute 'text_surface'
pygame.init()
screen = pygame.display.set_mode((1000,800))
clock = pygame.time.Clock()
pygame.display.set_caption('The Chieftain')
test_surface = pygame.image.load('ChieftainGameFolder/Pictures/Game Background/background.PNG').convert_alpha()
tw = test_surface.get_width()
th = test_surface.get_height()
#place elements here, what makes the game run
test_surface2 = pygame.transform.scale(test_surface, (tw * 1.11482720178 ,th * 1.12201963534))
text_font = pygame.font.SysFont("Arial",30)
def draw_text(text, font, text_col, x, y):
img = font.render(text,True,text_col,)
screen.blit(img, (x,y))
TEXT_COL = (255,255,255)
#gameloop
while True:
for event in pygame.event.get():
if event.type == pygame.QUIT:
pygame.quit()
exit()
draw_text("Chieftain", text_font, (0,0,0), 500, 400)
screen.blit(test_surface2,(0,0))
screen.blit(pygame.surface.Surface.text_surface, (500,400))
pygame.display.flip()
pygame.display.update()
clock.tick(60)
第一个 blit 背景,下一个 blit 按钮,然后是
draw_text()
screen.blit(test_surface2,(0,0))
screen.blit(pygame.surface.Surface.text_surface, (500,400))
draw_text("Chieftain", text_font, (0,0,0), 500, 400)
仅此而已。