2017-10-08 8 views
1

마우스를 클릭했을 때 마우스 위치에 원을 그리고 싶지만 작동하지 않습니다. 인터넷을 통해 들려오는 것처럼 while 루프 안에 있지만 여전히 작동하지 않습니다. 누군가 제발 도와 줄 수 있어요. 감사.마우스 클릭시 동그라미가 그려지지 않습니다 (파이 게임)

pygame.draw.circle(screen, planet_color, (circ), planet_radius, 0) 

항상 오류 로그를 확인하십시오 :

pygame.draw.circle(screen, planet_color, (circa), planet_radius, 0) 

을 코딩 할 때

def run_game(): 
    screen_height = 670 
    screen_width = 1270 
    pygame.init() 
    screen = pygame.display.set_mode((screen_width, screen_height)) 
    screen.fill((10,10,30)) 
    running = True 

    pygame.display.flip() 
    while running: 
     planet_color = (255,0,0) 
     planet_radius = 100 
     circ = pygame.mouse.get_pos() 
     for event in pygame.event.get(): 
      if event.type == pygame.QUIT: 
       running = False 
      elif event.type == pygame.MOUSEBUTTONDOWN: 
       pygame.draw.circle(screen, planet_color, (circa), planet_radius, 0) 
      elif event.type == pygame.KEYDOWN: 
       if event.key == pygame.K_q: 
        running = False 


run_game() 

답변

1

당신은 당신이 입력하는 의미 생각 오타 실수를 만든 곳이 당신을 말해야한다

+0

방금 ​​수정했지만 여전히 작동하지 않습니다. –

0

디스플레이를 업데이트하려면 pygame.display.flip()으로 전화해야하며 물론를 수정해야합니다./circa typo.

몇 가지 제안 사항 : pygame.time.Clock을 추가하여 프레임 속도를 제한하십시오.

마우스 이벤트는속성을 가지고 있으므로 circ 변수를 event.pos으로 바꿀 수 있습니다.

planet_colorplanet_radius은 while 루프 외부에서 정의 할 수 있습니다.

planet_color = (255,0,0) 
planet_radius = 100 
clock = pygame.time.Clock() 

while running: 
    for event in pygame.event.get(): 
     if event.type == pygame.QUIT: 
      running = False 
     elif event.type == pygame.MOUSEBUTTONDOWN: 
      pygame.draw.circle(screen, planet_color, event.pos, planet_radius) 
     elif event.type == pygame.KEYDOWN: 
      if event.key == pygame.K_q: 
       running = False 

    pygame.display.flip() # Call flip() each frame. 
    clock.tick(60) # Limit the game to 60 fps.