Pygame文字不会消失

时间:2015-02-15 16:29:52

标签: image pygame

所以我一直在做一个游戏,并且由于一些奇怪的原因,在level1函数中,我认为如果我有一个带有leveltext1 = false的while循环,那么我可以将文本写入屏幕,然后等待2秒然后make 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()

1 个答案:

答案 0 :(得分:0)

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