0

I am trying to make a monopoly game. But some display problems occur. When someone buy the house or something, its money will update to a new value. And the screen displace of the money will change. But in my code, the previous display value will not be covered or disappear, and the current value and previous value will display on the screen at the same time. The 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)

I hope to see that the previous value will disappear after updating

1 Answers1

0

Your question is related to this StackOverflow post: Update Text in Pygame

Maybe it answers your question

  • But I have a problem. I didn't build rect to put in my text because I have multiple text to output. The method to display multiple lines was refered to https://stackoverflow.com/questions/42014195/rendering-text-with-multiple-lines-in-pygame Is there any others ways to solve the problems? – 林育正 Dec 28 '22 at 06:05
  • Can you share the complete code or a working example? – Hammad Ali Butt Dec 28 '22 at 12:39