TypeError:找不到必需的参数'DEST'(位置2)

TypeError: Required argument #39;dest#39; (pos 2) not found(TypeError:找不到必需的参数#39;DEST#39;(位置2))

本文介绍了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()

截图:

这篇关于TypeError:找不到必需的参数&#39;DEST&#39;(位置2)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!

本文标题为:TypeError:找不到必需的参数&#39;DEST&#39;(位置2)

基础教程推荐