Mac OS X 10.7.3上的Pygame issuse [英] Pygame issuse on mac os x 10.7.3

查看:76
本文介绍了Mac OS X 10.7.3上的Pygame issuse的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

因此,我从Mac Lion中的python开始,并且尝试使用图像制作我的第一个程序: 这是程序的代码

So, I am starting with python in a mac Lion, and I am trying to make my first program with an image: here is the code of the program

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安装有关,但我不确定

INFO: Instead of an image I used a surface and It worked good. I suspect the problem might be related to my pygame installation but I'm not sure

推荐答案

在Python 2.6(Mac OS X 10.6)上,您的代码实际上对我来说是开箱即用"的.

Your code actually worked "out of the box" for me on Python 2.6 (Mac OS X 10.6).

如果您使用的是操作系统(Apple 2.7)附带的Python版本,请确保使用以下软件包:

If you're using the Python version supplied with your OS (Apple 2.7) make sure you're using this package: Pygame for Apple supplied Python - Mac OS X 10.7 .

这篇关于Mac OS X 10.7.3上的Pygame issuse的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆