如何更新文本



我正在尝试制作一款大富翁游戏。但是出现了一些显示问题。当有人买了房子或其他东西,它的钱会更新到一个新的价值。钱在屏幕上的位置也会改变。但是在我的代码中,前面的显示值不会被覆盖或消失,当前值和前面的值会同时显示在屏幕上。Render_mulit_line

import pygame
size = (1400, 924)
screen = pygame.display.set_mode(size)

class related_information_about_player():
def __init__(self, player, x_pos, y_pos):
self.name = player.name
self.money = player.money
self.player = player
self.x_pos = x_pos
self.y_pos = y_pos
self.text_input = (f"name: {self.name}nmoney: {self.player.money}")
def update(self):
self.text_input = (f"name: {self.name}nmoney: {self.player.money")
def render_multi_line(text, x, y, fsize):
global screen
lines = text.split("n")
for i, l in enumerate(lines):
screen.blit(main_font.render(l, True, white), (x, y + size*i))
#main function and I have deleted other irrelated code
information1.update()
information2.update()
information3.update()
information4.update()
render_multi_line(information1.text_input,
information1.x_pos, information1.y_pos, 22)
render_multi_line(information2.text_input,
information2.x_pos, information2.y_pos, 22)
render_multi_line(information3.text_input,
information3.x_pos, information3.y_pos, 22)
render_multi_line(information4.text_input,
information4.x_pos, information4.y_pos, 22)
[enter image description here](https://i.stack.imgur.com/KP2xs.png)

我希望看到之前的值在更新

后会消失

你的问题与这个StackOverflow帖子有关:更新Pygame

文本也许它回答了你的问题

最新更新