0

非常に単純なpyGameで割り当てを行っています。ウィンドウに画像をロードする必要がありますが、ロードされません! そして、IDLEにはエラーが表示されません..画像への相対パス(room.png)と絶対パス(C:... \ room.png)を試しましたが、何もしませんでした。これが私のコードです。

import pygame, sys      #import pygame and system library
from pygame import *    #import all pygame sublibs

pygame.init()
screen = display.set_mode((385,384))    #set screen size
display.set_caption("Blit example")
                        #this one gets the current working directory
background_file_name = "room.png"           #import bg
background_surface = pygame.image.load(background_file_name)    #use bg

while True:
        for e in pygame.event.get():
                if e.type==QUIT:        #break the loop and quit
                        pygame.quit()
                        sys.exit()
                        break


screen.fill((255,0,255))            #fill the screen with magenta
screen.blit(background_surface, (0,0))
display.update()
4

2 に答える 2

1

コメントでプログラミングについて何も知らないと言ったので、Python でインデントが重要であることをおそらく知らないでしょう。while ループは継続的に実行され、終了信号を待っています。しかし、表示はその後にのみ実行されます...

while True:
    for e in pygame.event.get():
            if e.type==QUIT:        #break the loop and quit
                    pygame.quit()
                    sys.exit()
                    break


    screen.fill((255,0,255))            #fill the screen with magenta
    screen.blit(background_surface, (0,0))
    display.update()

表示コードが while ループ内にあるようになりました

于 2012-02-06T20:02:14.477 に答える