2014-02-07 34 views
0

我正在關注PyGame的教程,並且在其中一個教程中我們正在創建一個簡單的Space Invaders遊戲。我有幾個問題。sprite沒有出現在pygame和無效的rectstyle對象

  1. 宇宙飛船精靈不會顯示在屏幕上,2.我得到一個錯誤。 (下面是詳細介紹)

代碼:

import pygame, sys 
from pygame.locals import * 

clock = pygame.time.Clock() #framerate 

size = x,y=800,600 
screen = pygame.display.set_mode((size)) #creates window, with resolution of 1600,900 

pygame.mouse.set_visible(0) 

ship = pygame.image.load('ship.png') 

ship_top = screen.get_height() - ship.get_height() #makes it so ship is in the centre at the bottom 
ship_left = screen.get_width()/2 - ship.get_width()/2 




while True: #main game loop 
    for event in pygame.event.get(): 
     if event.type == QUIT: 
      pygame.quit() 
      sys.exit() 
    screen.fill(0,0,0) 
    screen.blit(ship,(ship_left,ship_top)) 



    clock.tick(60) 
    pygame.display.update 

錯誤:

Traceback (most recent call last): 
    File "D:\python_tuts\space_invaders.py", line 24, in <module> 
    screen.fill(0,0,0) 
ValueError: invalid rectstyle object 

所以精靈不顯示,我得到這個錯誤。

感謝,

回答

3

填充方法是這樣的:

fill(color, rect=None, special_flags=0) -> Rect 

既然你都這樣稱它:

screen.fill(0,0,0) 

它指定0到RECT和special_flags。我想你的意思是這樣:

screen.fill((0,0,0)) 

它甚至更好,在你的代碼的開始定義顏色元組

BLACK = (0,0,0) 
screen.fill(BLACK)