我正在关注PyGame的教程,在本教程中我们正在创建一个简单的Space Invaders游戏。我有一些问题。
代码:
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
所以精灵没有显示,我得到了那个错误。
谢谢,
答案 0 :(得分:3)
填充方法如下所示:
fill(color, rect=None, special_flags=0) -> Rect
因为你这样称呼它:
screen.fill(0,0,0)
它为rect和special_flags分配0。我想你打算这样做:
screen.fill((0,0,0))
在代码开头定义颜色元组更好
BLACK = (0,0,0)
screen.fill(BLACK)