2017-10-05 26 views
0

私はpygameとPythonには一般的に新しいです。私は同様の質問をした他のスレッドを調べましたが、異なる解決策に達したようです。誰かが自分のコードに何が間違っているか教えてください。パイゲームは黒い画面しか表示しませんか?

import pygame 
import sys 

pygame.init() 

size = (width, height) = (720, 720) 

background_color = (0, 255, 0) 

screen = pygame.display.set_mode(size) 

ball = pygame.image.load("img/pokeball.jpg") 
speed = [2, 3] 

ballrect = ball.get_rect() 

ballrect.move_ip(0, 0) 

while True: 

    for event in pygame.event.get(): 
     if event.type == pygame.QUIT: sys.exit() 

ballrect = ballrect.move(speed) 

if ballrect.left < 0 or ballrect.right > width: 
    speed[0] = -speed[0] 

if ballrect.top < 0 or ballrect.bottom > height: 
    speed[1] = -speed[1] 

screen.fill(background_color) 
screen.blit(ball, ballrect) 
pygame.display.flip() 
+1

インデントを確認してください。私はかなり真っ先にすべてを確信しています:そのループにいるはずです。 –

+0

ありがとうございます。今私はこの質問を削除することができますしたい – Neo

答えて

0

正しいインデントと協力して(任意ループ(while、...)又はif文の4つのスペースのインデント):

import pygame 
import sys 

pygame.init() 

size = (width, height) = (720, 720) 

background_color = (0, 255, 0) 

screen = pygame.display.set_mode(size) 

ball = pygame.image.load("/absolute_path/pokeball.jpg") 
speed = [2, 3] 

ballrect = ball.get_rect() 

ballrect.move_ip(0, 0) 

while True: 

    for event in pygame.event.get(): 

     if event.type == pygame.QUIT: sys.exit() 

     ballrect = ballrect.move(speed) 

     if ballrect.left < 0 or ballrect.right > width: 
      speed[0] = -speed[0] 

     if ballrect.top < 0 or ballrect.bottom > height: 
      speed[1] = -speed[1] 

    screen.fill(background_color) 
    screen.blit(ball, ballrect) 
    pygame.display.flip() 

iも

を.jpgのボールの絶対パスを使用
関連する問題