2012-08-22 6 views
0

파이 게임으로 팩맨 게임을 만들려고하는데 몇 가지 문제가 있습니다. '음식'에는 이미지가 없다는 말입니다.파이 게임 이미지 AttributeError

이것은 내 팩맨 게임입니다. [code redacted]

문제는이 지역 뭔가 잘못 여기이며 그 음식이 모든 관련이없는 비트를 제거 어떤 속성 이미지

class Food(pygame.sprite.Sprite): 
    def __init__(self,x,y,color): 
     pygame.sprite.Sprite.__init__(self) 

     pygame.image = pygame.Surface([7,7]) 
     self.image.fill(color) 

     self.rect = self.image.get_rect() 
     self.rect.top = y 
     self.rect.left = x 
    def update (self,player): 
     collidePlayer = pygame.sprite.spritecollide(self,player,False) 
     if collidePlayer: 
      food.remove 
+0

어디서나 오류가 표시되지 않습니다. –

답변

1

이없는 다음과 같은 스프라이트 하위 클래스 '__init__ 방법의 차이를 볼 수 있습니까 나에게 말한다?

class Wall(pygame.sprite.Sprite): 

    def __init__(self,x,y,width,height, color):#For when the walls are set up later 
     pygame.sprite.Sprite.__init__(self) 

     self.image = pygame.Surface([width, height]) # <------------- 
     self.image.fill(color) 

class player(pygame.sprite.Sprite): 

    def __init__ (self,x,y): 

     pygame.sprite.Sprite.__init__(self) 

     self.image = pygame.Surface([13,13]) # <------------- 
     self.image.fill(white) 

class Food(pygame.sprite.Sprite) 
    def __init__(self,x,y,color): 
     pygame.sprite.Sprite.__init__(self) 

     pygame.image = pygame.Surface([7,7]) # <----- this one is different! 
     self.image.fill(color) 

당신이 self 당신이 self.image을 설정하지 않은 때문에 image 속성이없는 없다는 오류를 얻고있는 이유는, 당신은 pygame 모듈 자체에 이미지를 저장.

PS :

 food.remove 

모양의 선이 나에게 의심스러운 것 같다. remove이 메서드 인 경우 food.remove()이 호출되고 food.remove은 아무 것도 수행하지 않습니다.

+0

감사합니다. 그래, 나는 그것이 food.remove() 일 것임을 확신한다.하지만 나는 가서 그걸 확인해 볼 시간이 없었다. – user1615699