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()
我想加载此图片,然后将其向前移动。当我用矩形替换图像(船)时它工作正常。我将图像保存在空闲文件中,我保留了已成功加载的所有其他图像。