【问题标题】:Pygame text not going awayPygame 文本不会消失
【发布时间】:2015-02-15 16:29:51
【问题描述】:

所以我一直在开发一款游戏,出于某种奇怪的原因,我想如果我有一个 leveltext1 = false 的 while 循环,那么我可以将文本写到屏幕上,然后等待 2 秒然后使 level1text = true 它会消失。估计没... 代码:

#!/usr/bin/python
import pygame
import time
pygame.init()
blue = (25,25,112)

black = (0,0,0)
red = (200,0,0)

bright_red = (255,0,0)
white = (255,255,255)

groundcolor = (139,69,19)

green = (80,80,80)

other_green = (110,110,110)

lives = 0

gameDisplay = pygame.display.set_mode((1336,768))
pygame.display.set_caption("TheAviGame")
direction = 'none'
clock = pygame.time.Clock()

img = pygame.image.load('guyy.bmp')

famousdude = pygame.image.load('kitten1.bmp')

kitten = pygame.image.load('macharacterbrah.bmp')

dorritosman = pygame.image.load('Doritos.bmp')

backround = pygame.image.load('backroundd.bmp')

playernormal = pygame.image.load('normalguy.bmp')

playerocket = pygame.image.load('rocketguyy.bmp')

rocketcat = pygame.image.load('jetpackcat.bmp')

mlglogo = pygame.image.load('mlg.bmp')

level1bg = pygame.image.load('level1background.bmp')






def mts(text, textcolor, x, y, fs):
    font = pygame.font.Font(None,fs)
    text = font.render(text, True, textcolor)
    gameDisplay.blit(text, [x,y])
def button(x,y,w,h,ic,ac):
    mouse = pygame.mouse.get_pos()
    click = pygame.mouse.get_pressed()

    if x+w > mouse[0] > x and y+h > mouse[1] > y:
        pygame.draw.rect(gameDisplay, ac,(x,y,w,h))

        if click[0] == 1:
            gameloop()       
    else:
        pygame.draw.rect(gameDisplay, ic,(x,y,w,h))
def game_intro():

        intro = True

        while intro:
            for event in pygame.event.get():
                #print(event)
                if event.type == pygame.QUIT:
                    pygame.quit()
                    quit()

            gameDisplay.fill(black)     

            button(450,450,250,70,green,other_green)
            mts("Play", white, 540, 470, 50)
            mts("THE AVI GAME", red, 380, 100, 100)
            gameDisplay.blit(famousdude, (100,100))
            gameDisplay.blit(kitten, (700,300))
            gameDisplay.blit(dorritosman, (1000,400))


            pygame.display.update()
            clock.tick(15)
def gameloop():
    imgx = 1000
    imgy = 100
    while True:

        for event in pygame.event.get():
            if event.type == pygame.QUIT:
                pygame.quit()
                quit()
            if event.type == pygame.KEYDOWN:
                if event.key == pygame.K_RIGHT:
                    imgx += 10

        gameDisplay.blit(backround, (30,30))
        gameDisplay.blit(rocketcat, (imgx,imgy))

        pygame.display.update()
        clock.tick(15)
def level1():
    imgx = 500
    imgy = 500
    leveltext = False
    while True:
        for event in pygame.event.get():
            if event.type == pygame.QUIT:
                pygame.quit()
                quit()
        while not leveltext:
                gameDisplay.blit(level1bg, (0,0))
                mts("LEVEL 1:", red, 450, 220, 60)
                mts('Controls: W or Up to move up.', white, 450, 300, 40)
                mts('Controls: A or Left to move left.', white, 450, 340, 40)
                mts('Controls: S or Down to move down.', white, 450, 390, 40)
                mts('Controls: D or Right to move Right.', white, 450, 430, 40)
                time.sleep(2)
                leveltext = True

        pygame.display.update()
level1()

【问题讨论】:

    标签: image pygame


    【解决方案1】:

    据我了解,当您将文本粘贴到表面上时,它会永久成为该表面的一部分。如果您希望字体消失,您可以尝试将其 blitting 到该表面的副本上,然后将更改后的表面 blit 到显示器。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2018-02-08
      • 2016-07-29
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2020-11-11
      • 1970-01-01
      相关资源
      最近更新 更多