pygame.error不支持的图像格式 [英] pygame.error Unsupported image format

查看:217
本文介绍了pygame.error不支持的图像格式的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

使用pygame'1.9.2pre'运行python 3.3.0,遵循了python的新教程,老实说看不到我出了错,看起来和教程上的一样,但是已经有4年的历史了.感谢您的帮助!

running Python 3.3.0 with pygame '1.9.2pre', following a tutorial, new to python, honestly cant see where i've gone wrong, looks the same as on the tutorial, however it is 4 years old. Thanks for help!

我收到错误-两者都不支持的图像格式.我已经尝试过jpg和png,版本规格说明它同时支持这两种格式.

I get error - unsupported image format for both. I've tried jpg and png, the version spec says it supports them both.

bif ="bg.jpg"
mif ="man.jpg"
import pygame, sys
from pygame.locals import *

pygame.init()

screen = pygame.display.set_mode((1100,750),0,32)
background = pygame.image.load(bif).convert()
mouse_c = pygame.image.load(mif).convert_alpha()


Running = True

while Running:
    for event in pygame.event.get():
        if event.type == QUIT:
            pygame.quit()
            Running = False
            sys.exit()
            break

    screen.blit(background,(0,0))

    x,y = pygame.mouse.get_pos()
    x -= mouse_r.get_width()/2
    y -= mouse_r.get_height()/2

    screen.blit(mouse_r,(x,y))

    pygame.display.update()

推荐答案

也许您在此处使用了错误的变量名:

Perhaps you've used the wrong variable name here:

x,y = pygame.mouse.get_pos()
x -= mouse_r.get_width()/2
y -= mouse_r.get_height()/2

screen.blit(mouse_r,(x,y))

我之前已经看过相同的教程,并且看来 mouse_r应该是 mouse_c .

I've watched the same tutorial before and it seems that mouse_r should be mouse_c.

在加载图像时尝试使用完整的目录路径名:

Try using the full directory path name while loading the images:

import os
bif = os.getcwd() + "\\bg.jpg"
mif = os.getcwd() + "\\man.jpg"

这篇关于pygame.error不支持的图像格式的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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