だから、私はマックライオンでのpythonを始めています、と私はイメージと私の最初のプログラムを作成しようとしています:ここ はプログラムpygameのダウンロードissuse X 10.7.3
import pygame, sys
from pygame.locals import *
pygame.init()
FPS = 30
fpsClock = pygame.time.Clock()
DISPLAYSURF = pygame.display.set_mode((400, 300), 0, 32)
pygame.display.set_caption('Animation');
WHITE = (255, 255, 255)
catImg = pygame.image.load("cat.png")
catx = 10
caty = 10
direction = 'right'
while True:
DISPLAYSURF.fill(WHITE)
if direction == 'right':
catx += 5
if catx == 280:
direction = 'down'
elif direction == 'down':
caty += 5
if caty == 220:
direction = 'left'
elif direction == 'left':
catx -= 5
if catx == 10:
direction = 'up'
elif direction == 'up':
caty -= 5
if caty == 10:
direction = 'right'
DISPLAYSURF.blit(catImg, (catx, caty))
for event in pygame.event.get():
if event.type == QUIT:
pygame.quit()
sys.exit()
pygame.display.update()
fpsClock.tick(FPS)
のコードですプログラムを実行すると
、間違いがあります:
Traceback (most recent call last):
File "catanimation.py", line 13, in <module>
catImg = pygame.image.load("cat.png")
pygame.error: File is not a Windows BMP file
INFOこの問題の原因である可能性がありますどのような:代わりに、私は表面を使用し、それは良い働いた画像の。私は問題が私のpygameのインストールに関連している可能性が疑わしいですが、私は確信していません
ライオンはosx 10.7です。エラーメッセージは、ファイルが有効なWindows形式のBMP形式ではないと主張しています。それはあなたがチェックすべきものです。どのようにイメージを生成しましたか? – bdares
私はインターネットからダウンロードしました。http://inventwithpython.com/cat.png –
ファイル拡張子を "png"にして、bmpとして読むのではなく、pngとして読み込んでください。 pngをbmpとして扱うことはできません。 – bdares