Pygame文字没有画画

时间:2014-07-07 21:16:49

标签: python pygame

这个类应该管理“调试菜单”(FPS和敌人数量),所以我想在窗口的左角绘制这些信息,但文本没有出现。 上课:

class Debug_mode():
    def __init__(self):
        self.font= pygame.font.Font(None, 48)

    def get_strings(self,clock,enemy):
        self.string1= "FPS: " + str(int(clock.get_fps()))
        self.string2= "Enemigos: " + str(enemy.min_enemies)
        self.text1= self.font.render(self.string1, True, (255,255,255))
        self.text2= self.font.render(self.string2, True, (255,255,255))


    def render(self,surface):
        surface.blit(self.text1,(500,500))
        surface.blit(self.text2,(500,100))

主要功能:

def main():
    pygame.init()
    pygame.mouse.set_visible(False)
    Screen_Surface= pygame.display.set_mode((WIDTH,HEIGHT))
    background_image= pygame.image.load("C:/Users/Aitor/Desktop/bg.png").convert()
    FPS_Clock= pygame.time.Clock()
    vx= 0
    vy= 0
    left_pressed= False
    right_pressed= False
    down_pressed= False
    up_pressed= False
    Toby= Player()
    Odyn= Enemies()
    cursor= Cursor()
    debug_menu= Debug_mode()

    while True:
        FPS_Clock.tick(FPS)
        mouse_pos= pygame.mouse.get_pos()
        old_x= Toby.rect.left
        old_y= Toby.rect.top

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

            if event.type == pygame.KEYDOWN:
                if event.key == pygame.K_LEFT:
                    left_pressed= True
                    vx= -Toby.speed
                if event.key == pygame.K_RIGHT:
                    right_pressed= True
                    vx= Toby.speed
                if event.key == pygame.K_UP:
                    up_pressed= True
                    vy= -Toby.speed
                if event.key == pygame.K_DOWN:
                    down_pressed= True
                    vy= Toby.speed

            if event.type == pygame.KEYUP:
                if event.key == pygame.K_LEFT:
                    left_pressed= False
                    if right_pressed:
                        vx= Toby.speed
                    else:
                        vx= 0
                if event.key == pygame.K_RIGHT:
                    right_pressed= False
                    if left_pressed:
                        vx= -Toby.speed
                    else:
                        vx= 0
                if event.key == pygame.K_DOWN:
                    down_pressed= False
                    if up_pressed:
                        vy= -Toby.speed
                    else:
                        vy= 0
                if event.key == pygame.K_UP:
                    up_pressed= False
                    if down_pressed:
                        vy= Toby.speed
                    else:
                        vy= 0

            if event.type == pygame.MOUSEMOTION:
                (Toby.rect.left, Toby.rect.top)= mouse_pos


        Toby.move(vx, vy, old_x, old_y)
        Screen_Surface.blit(background_image, [0,0])
        Odyn.update(Screen_Surface)
        Screen_Surface.blit(Toby.image,Toby.rect)
        pygame.display.update()
        debug_menu.get_strings(FPS_Clock,Odyn)
        debug_menu.render(Screen_Surface)

1 个答案:

答案 0 :(得分:1)

update()

之前执行此操作
    debug_menu.get_strings(FPS_Clock,Odyn)
    debug_menu.render(Screen_Surface)

    pygame.display.update()