2011-12-09 3 views
2

저는 파이 게임에서 rect 내에서 클릭했는지 여부를 감지하는 방법을 찾을 수 없습니다. 나중에Python에서 rect를 클릭하기위한 테스트

if self.click: #(this is true if mouse button is down) 
     if self.mouserect.colliderect(self.a_thing_to_click_on.rect): 
      do_stuff 

다음

self.mouserect=(pygame.mouse.get_pos(), 8,8) 

및 시도하지만 나에게 AttributeError을 제공합니다 : '튜플'개체가 어떤 속성 'colliderect를'이 없습니다. 내가 도대체 ​​뭘 잘못하고있는 겁니까?

답변

0

터플을 self.mouserect에 할당하고 Rect이 아닌 튜플을 할당합니다. 이 솔루션은 주위에 Rect을 래핑하는 것입니다 :

self.mouserect=pygame.Rect(pygame.mouse.get_pos(), (8,8)) 
+0

저에게 제공합니다. TypeError : 인수는 rect 스타일 객체 여야합니다 ... – Alex

+0

정확히 어떤 줄에 있습니까? – Ikke

1

당신은 rect.collidepoint()를 사용하려고 했습니까?

if self.click: #(this is true if mouse button is down) 
    if self.a_thing_to_click_on.rect.collidepoint(pygame.mouse.get_pos()): 
관련 문제