1

だから、私は Mac Lion で python から始めて、画像を使って最初のプログラムを作ろうとしています: ここにプログラムのコードがあります

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

この問題の原因は何ですか

情報: 画像の代わりにサーフェスを使用しましたが、うまくいきました。問題は pygame のインストールに関連している可能性があると思われますが、よくわかりません

4

1 に答える 1

3

あなたのコードは、Python 2.6(Mac OS X 10.6)で実際に「箱から出して」動作しました。

OS に付属の Python バージョン (Apple 2.7) を使用している場合は、次のパッケージを使用していることを確認してください: Apple が提供する Python 用の Pygame - Mac OS X 10.7

于 2012-04-11T22:37:25.347 に答える