2014-02-07 4 views
0

파이 게임에 대한 지침서를 따르고 있으며 간단한 스페이스 인베이더 게임을 작성 중입니다. 나는 몇 가지 문제가있다.파이 게임 및 유효하지 않은 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 

당신이 이런 식으로 호출되기 때문에 : 그것은 사각형과 special_flags 0을 할당

screen.fill(0,0,0) 

. 나는이 작업을 수행하는 의미 생각 :

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

그것은 코드의 시작 부분에 컬러 튜플을 정의하는 데에도 더 나은

BLACK = (0,0,0) 
screen.fill(BLACK) 
관련 문제