簡體   English   中英

Pygame 在 mac os x 10.7.3 上的問題

[英]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.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM