Reputation: 69
I am following a tutorial on PyGame and in one of the tutorial we are creating a simple Space Invaders game. 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,
Upvotes: 0
Views: 1174
Reputation: 11180
The fill method looks like this:
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. 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)
Upvotes: 3