2017-04-07 111 views
-2

我試圖做一個射擊遊戲pygame的,但是當我跑我的遊戲,它顯示pygame的窗口,而是給出了一個錯誤:類型錯誤:必需的參數「DEST」(位置2)未找到

Traceback (most recent call last): 
    File "C:\Users\Nnamdi\AppData\Local\Programs\Python\Python36-32\game.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() 

希望能幫到你。

+0

你能不能給我們整個的錯誤? – Rishav

+0

'dest'是什麼? – eyllanesc

+0

您的錯誤['SCREEN.blit(text)']中的第26行和您發佈的代碼['SCREEN.blit(text,dest)']中的第26行(當前)明顯不同。這使得其中一個不正確。 – donkopotamus

回答

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

+0

@LillyM。更新我的解決方案 – eyllanesc

相關問題