Python 为什么这个图像不能在pygame中打开?
我想加载此图像,然后将其前后移动。当我用矩形替换图像(船)时,效果很好。我将该图像保存在空闲文件中,在该文件中我保存了所有其他已成功加载的图像。您是否可以尝试消除不会导致问题的部分并发布一条消息?您可能没有将FinalBoat.png放在python程序所在的同一目录中。您的代码在我的计算机上运行。如果您调用image.load时知道是否有任何错误消息,那就太好了。另一个失败的可能性是pygame可能没有使用对PNG图像的支持进行编译。@jcoppens:函数支持.PNGfiles@elegent我知道它可以支持它们,但请看这里:这意味着pygame可能是在没有png支持的情况下构建的。OP应执行所述测试,以查看是否内置了支持。Python 为什么这个图像不能在pygame中打开?,python,python-2.7,pygame,Python,Python 2.7,Pygame,我想加载此图像,然后将其前后移动。当我用矩形替换图像(船)时,效果很好。我将该图像保存在空闲文件中,在该文件中我保存了所有其他已成功加载的图像。您是否可以尝试消除不会导致问题的部分并发布一条消息?您可能没有将FinalBoat.png放在python程序所在的同一目录中。您的代码在我的计算机上运行。如果您调用image.load时知道是否有任何错误消息,那就太好了。另一个失败的可能性是pygame可能没有使用对PNG图像的支持进行编译。@jcoppens:函数支持.PNGfiles@elegen
def function():
import pygame
import time
from pygame.locals import *
pygame.init()
Width = 272
Height = 552
white = 255,255,255
blue = 0,255,255
red = 255,0,0
Left_Rect = pygame.Rect(0,452,135,100)
Right_Rect = pygame.Rect(137,452,135,100)
Location = 136
WaterLevel = 452
Depth = 100
CLOCK = pygame.time.Clock()
FPS = 30
gameDisplay = pygame.display.set_mode((Width,Height))
pygame.display.set_caption('boat game')
######## This is the image that will not open ############################
boat = pygame.image.load("FinalBoat.png").convert_alpha()
boat = pygame.transform.scale(boat, (40, 20))
stop = False
gameDisplay.fill(white)
pygame.display.update()
is_Left = False
is_Right = False
while not stop:
####### CONTROLLES ####################################################
pygame.draw.rect(gameDisplay, red, Left_Rect)
pygame.draw.rect(gameDisplay, red, Right_Rect)
####### BOAT #########################################################
gameDisplay.blit(boat, (Location,WaterLevel-20))
####### WATER ########################################################
pygame.draw.rect(gameDisplay,blue,(0,WaterLevel,272,Depth))
WaterLevel -= 1
Depth += 1
pygame.display.update()
######################################################################
for event in pygame.event.get():
print event
if event.type == pygame.MOUSEBUTTONDOWN:
is_Left = Left_Rect.collidepoint(pygame.mouse.get_pos())
is_Right = Right_Rect.collidepoint(pygame.mouse.get_pos())
if event.type == pygame.MOUSEBUTTONUP:
is_Left = False
is_Right = False
if event.type == pygame.QUIT:
pygame.quit()
quit()
if is_Left:
Location -= 5
elif is_Right:
Location += 5
CLOCK.tick(FPS)
pygame.display.update()
function()