[英]sprite not showing up in pygame & invalid rectstyle object
I am following a tutorial on PyGame and in one of the tutorial we are creating a simple Space Invaders game. 我正在关注PyGame上的一个教程,在其中一个教程中,我们正在创建一个简单的Space Invaders游戏。 I have a few problems.
我有几个问题。
Code: 码:
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
Error: 错误:
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
So the sprites do not show, and I get that error. 所以精灵不显示,我得到那个错误。
Thanks, 谢谢,
The fill method looks like this: fill方法如下所示:
fill(color, rect=None, special_flags=0) -> Rect
Since you are calling it like this: 由于您这样称呼它:
screen.fill(0,0,0)
It assigns 0 to rect and special_flags. 它将0分配给rect和special_flags。 I think you meant to do this:
我认为您打算这样做:
screen.fill((0,0,0))
It's even better to define color tuples at the start of your code 最好在代码开始时定义颜色元组
BLACK = (0,0,0)
screen.fill(BLACK)
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.