TypeError:找不到必需的参数';DEST';(位置2)
问题描述
我正尝试用pyGame制作射击游戏,但当我运行游戏时,它显示了pyGame窗口,但出现错误:
Traceback (most recent call last):
File "C:UsersNnamdiAppDataLocalProgramsPythonPython36-32game.py", line 26, in <module>
SCREEN.blit(text)
TypeError: Required argument 'dest' (pos 2) not found
以下是我的代码:
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()
希望您能帮忙。
解决方案
您必须定义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()
截图:
相关文章