- 此问题在此处已有答案**:
Updating text in pygame(1个答案)
1小时前关闭。
我正在尝试做一个大富翁游戏。但是一些显示问题出现了。当某人买了房子或什么东西,它的钱会更新到一个新的值。并且钱的屏幕位移会改变。但是在我的代码中,以前显示的值不会被覆盖或消失,并且当前值和以前的值会同时显示在屏幕上。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)
我希望看到更新后以前的值会消失
1条答案
按热度按时间o7jaxewo1#
您的问题与此StackOverflow帖子相关:Update Text in Pygame
也许它回答了你的问题