2017-11-09 4 views
0

コードを実行すると、ウィンドウが自動的にクラッシュします。私は理由について何か理由を見つけることができないようです。これは、ここでは、コードのコードの非常に単純な一片ので、コンテキストが必要とされていない:)境界チェック(pygame)を使用するプログラムを実行するとクラッシュする

次のとおりです。ここで

import pygame 
size=(0,0) 
WHITE=(255,255,255) 
BLACK=(0,0,0) 
rectX=(0) 
rectY=(0) 
rectSizeX=(100) 
rectSizeY=(100) 
screen=pygame.display.set_mode(size) 
screen.fill(WHITE) 
pygame.display.flip() 
while (True): 
    pygame.draw.rect(screen, BLACK, [rectX, rectY, rectSizeX, rectSizeY]) 
    pygame.display.flip() 
    mouse_pos = pygame.mouse.get_pos() 
    while mouse_pos[0] >= (rectX) and mouse_pos[1] >= (rectY) and mouse_pos[0] <= (rectX+rectSizeX) and mouse_pos[1] <= (rectY+rectSizeY): 
     print("meme") 
     mouse_pos = pygame.mouse.get_pos() 
+3

また今後の質問でも、あなたのコードだけでなく、エラーを投稿してください。 – voiDnyx

+0

Pythonシェルにエラーが表示されません。 pygame画面が応答を停止する –

+1

マウスイベントを正しく処理しないようです。これを見てくださいhttps://stackoverflow.com/questions/16285889/pygame-mouse-get-pos-not-working#16286076 – voiDnyx

答えて

0

は今の作業バージョンです:

import pygame 
import sys 
size=(0,0) 
WHITE=(255,255,255) 
BLACK=(0,0,0) 
rectX=(0) 
rectY=(0) 
rectSizeX=(100) 
rectSizeY=(100) 
screen=pygame.display.set_mode(size) 
screen.fill(WHITE) 

pygame.draw.rect(screen, BLACK, [rectX, rectY, rectSizeX, rectSizeY]) 
pygame.display.flip() 
mouse_pos = pygame.mouse.get_pos() 

while True: 
    for event in pygame.event.get(): 
     if event.type == pygame.MOUSEMOTION: 
      mouse_pos = pygame.mouse.get_pos() 
      if mouse_pos[0] >= (rectX) and mouse_pos[1] >= (rectY) and mouse_pos[0] <= (rectX+rectSizeX) and mouse_pos[1] <= (rectY+rectSizeY): 
       print("meme") 
      else: 
       print (mouse_pos) 
     if event.type == pygame.QUIT: 
      pygame.quit() 
      sys.exit() 

はまた、あなたの窓に注意してくださいあなたは "QUIT"タイプのイベントも処理する必要があるので、 "応答していません"が、それを閉じることはできません。

関連する問題