2015-04-24 66 views
2

這是我的代碼,我試圖讓一個矩形:類型錯誤:必須是pygame.Surface,就不一一列舉

import pygame 
import sys 
pygame.init() 
color = [255,20,78] 
black = [0,0,0] 
screen = pygame.display.set_mode((800,600), 0, 32) 
pygame.display.set_caption("Rectangle") 

while True: 
    for event in pygame.event.get(): 
     if event.type == pygame.QUIT: 
      pygame.quit() 
      sys.exit() 
    screen.fill(color) 
    pygame.draw.rect(color, black, [400,300,10,10]) 
    pygame.display.update() 

我不明白是什麼錯誤與表面 有人可以幫我指? 任何幫助表示讚賞! 哦,請不要向我發誓,我仍然是一個程序noob。 錯誤:

Traceback (most recent call last): 
    File "C:\Users\Hugo\Desktop\Pygame\game - kopie.py", line 15, in <module> 
    pygame.draw.rect(color, black, [400,300,10,10]) 
TypeError: must be pygame.Surface, not list 

回答

1

問題是線

pygame.draw.rect(color

如果顏色列表。

draw.rect需要Surface作爲第一個參數。

pygame.draw.rect() draw a rectangle shape rect(Surface, color, Rect, width=0) -> Rect Draws a rectangular shape on the Surface. The given Rect is the area of the rectangle. The width argument is the thickness to draw the outer edge. If width is zero then the rectangle will be filled.

Keep in mind the Surface.fill() method works just as well for drawing filled rectangles. In fact the Surface.fill() can be hardware accelerated on some platforms with both software and hardware display modes.

請通過Surface作爲第一個參數。

相關問題