1
我正在研究基於時間的pygame移動程序。我一直收到這個錯誤。錯誤:無法打開圖像
Traceback (most recent call last):
File "C:\Documents and Settings\Mohammad Raza\Desktop\Python
Scripts\TimeBasedMovement.py", line 11, in <module>
background = pygame.image.load(background_image_filename).convert()
error: Couldn't open Wolf.jpg
我想也許我刪除了圖像,但我檢查了圖像並沒有刪除。它被保存爲名稱「Wolf」並存儲爲JPEG圖像。
以下是整個代碼。
background_image_filename = 'Wolf.jpg'
sprite_image_filename = 'Cartoon.jpg'
import pygame
from pygame.locals import *
from sys import exit
pygame.init()
screen = pygame.display.set_mode((640,480),0,32)
background = pygame.image.load(background_image_filename).convert()
sprite = pygame.image.load(sprite_image_filename)
clock = pygame.time.Clock()
x = 0.
speed = 250
while True:
for event in pygame.event.get():
if event.type == QUIT:
exit()
screen.blit(background,(0,0))
screen.blit(sprite,(x,100))
time_passed = clock.tick()
time_passed_seconds = time_passed_seconds/1000.0
distance_moved = time_passed_seconds * speed
x += distance_moved
if x > 640.:
x -= 640.
pygame.display.update()
真實的,但是這不是問題的任擇議定書所問的問題。儘管可能需要指出OP代碼中的其他錯誤,但應該在註釋中提供此類幫助,因爲它們實際上並不回答所問的問題。 – Louis