TypeError:必需参数' dest' (pos 2)未找到

时间:2017-04-07 00:25:10

标签: python python-3.6

我试图用pygame制作一个射击游戏,但是当我运行我的游戏时,它会显示pygame窗口,但是会出错:

import pygame, sys
from pygame.locals import *

pygame.init()

ammo = "10" # you have ten ammo, use it wisely...

WIDTH = 600
HEIGHT = 600
SCREEN = pygame.display.set_mode((WIDTH, HEIGHT))

pygame.display.set_caption('Bomber')

WHITE = (255, 255, 255)
BLACK = (0, 0, 0)
RED = (255, 0, 0)
GREEN = (0, 255, 0)
BLUE = (0, 0, 255)
DARKBLUE = (2, 9, 129)
YELLOW = (255, 255, 255)

SCREEN.fill(DARKBLUE)
pygame.display.flip()
basicfont = pygame.font.SysFont(None, 48)
text = basicfont.render('Bomber', True, (255, 0, 0), (255, 255, 255))
SCREEN.blit(text, dest)
is_running = True
while is_running:
    for event in pygame.event.get():
        if event.type == pygame.QUIT:
            is_running = False
            pygame.quit()

这是我的代码:

{{1}}

希望你能提供帮助。

1 个答案:

答案 0 :(得分:0)

您必须定义dest变量。您还应该调用函数pygame.display.flip()。例如:

import pygame, sys
from pygame.locals import *

pygame.init()

ammo = "10" # you have ten ammo, use it wisely...

WIDTH = 600
HEIGHT = 600
SCREEN = pygame.display.set_mode((WIDTH, HEIGHT))

pygame.display.set_caption('Bomber')

WHITE = (255, 255, 255)
BLACK = (0, 0, 0)
RED = (255, 0, 0)
GREEN = (0, 255, 0)
BLUE = (0, 0, 255)
DARKBLUE = (2, 9, 129)
YELLOW = (255, 255, 255)

SCREEN.fill(DARKBLUE)
pygame.display.flip()
basicfont = pygame.font.SysFont(None, 48)
text = basicfont.render('Bomber', True, (255, 0, 0), (255, 255, 255))
dest = (100, 100)
is_running = True
while is_running:
    for event in pygame.event.get():
        if event.type == pygame.QUIT:
            is_running = False

    SCREEN.blit(text, dest)
    pygame.display.flip()

pygame.quit()

截图:

enter image description here