[英]Pygame issuse on mac os x 10.7.3
所以,我在 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 安装有关,但我不确定
您的代码实际上在 Python 2.6 (Mac OS X 10.6) 上对我“开箱即用”。
如果您使用的是随操作系统 (Apple 2.7) 提供的 Python 版本,请确保您使用的是此 package: Pygame for Apple 提供的 Python - Mac OS X 10.7 。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.