I want to make the text disappear from pygame pie game

Asked 2 years ago, Updated 2 years ago, 76 views

I'm making a pie game. If you get points while playing the game, you move on to the next game, and there's still a text about the score. I'm asking you a question because I can only see the text floating up and not going down again.

python pygame

2022-09-20 20:48

1 Answers

How do you display the text?

When I checked a simple sample of pygame, it was implemented by erasing it with a specific color (white) and redrawing it every time it was printed out, so I think I can hide it using isTextView at the time of redrawing.

The example below is an example of showing/hiding text every time you click.

import pygame

pygame.init()
WHITE = (255, 255, 255)
RED = (255, 0, 0)
screen = pygame.display.set_mode([200, 100])
done = False
clock = pygame.time.Clock()
isTextView = True;
font = pygame.font.Font(None, 32) #FontSetting
txt_surface = font.render ("This is Text", True, RED) #Text

while not done:
    clock.tick(10)

    for event in pygame.event.get():
        if event.type == pygame.QUIT:
            done = True
        If event.type == pygame.MOUSEBUTTONDOWN: # MouseClick Event
            isTextView = not isTextView;

    screen.fill(WHITE) #Fill the screen
    ifisTextView: # whether text is displayed
        screen.blit(txt_surface,(10, 10)) #text output

    pygame.display.flip()
pygame.quit()

If the implementation method is different and the above content cannot be resolved, please attach a simple code.

Thank you.


2022-09-20 20:48

If you have any answers or tips


© 2024 OneMinuteCode. All rights reserved.