0
\$\begingroup\$

At this moment, I can only display text once I stop updating and drawing sprites. In the code below (which is actually the game loop), you can see how if GAMEOVER == True (gameloop stops drawing), the text "Game Over!" is displayed. But if I try to display any text while drawing and updating, it doesn't appears until I stop drawing the sprites. In fact, the frist block to display text ("My Game!") isn't shown, as I said, until the gameloop stops drawing. I need to display some info like, name of char, instructions, etc while the game is running, so, how can I render text in every loops and frames?

The game loop:

while True:

    myfont = pygame.font.SysFont("monospace", 30)
    label = myfont.render("My Game!", 1, (255, 255, 0))
    SCREEN.blit(label, (500, 400))

    if PLAYER.healthBase <= 0:
        GAMEOVER = True #True para que se acabe la partida

    if not GAMEOVER:  
        charsGroup.update(time_passed)
        npcsGroup.update(time_passed)
        mapTilesGroup.draw(SCREEN)
        charsGroup.draw(SCREEN)
        npcsGroup.draw(SCREEN)
        drawBullets()

    for event in pygame.event.get():
        if event.type == pygame.QUIT:
            pygame.quit()
            sys.exit()

    time_passed = freq.tick(0) /1000.

    if GAMEOVER:
        myfont = pygame.font.SysFont("monospace", 30)
        label = myfont.render("GAME OVER!", 1, (255, 255, 0))
        SCREEN.blit(label, (400, 300))


    pygame.display.flip()
\$\endgroup\$
0
\$\begingroup\$

Are the sprites drawing over the text?

Text isn't a special thing, it's just another sprite you render to the screen (albeit one you generate in a special way).

If you render the text and then at the same position render a sprite you won't see the text because there is something in front of it.

Render the texts after rendering the sprites.

\$\endgroup\$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.