0
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()

I want to load this image and then move it back in forth. When I replace the image(boat) with a rectangle it works fine. I keep the image in the idle file where I have kept all the other images that have been loaded successfully.

  • Can you try to eliminate parts that aren't causing the problem and post an [MCVE](http://stackoverflow.com/help/mcve)? – KSFT Apr 03 '15 at 01:45
  • 1
    You have not probably place FinalBoat.png at the same directory where the python program lies. Your code runs on my computer. – Mestica Apr 03 '15 at 01:50
  • It would be nice to nice to know if there is any error message when you call the image.load. Another possibility for failure is that maybe pygame is not compiled with support for PNG images. – jcoppens Apr 03 '15 at 05:06
  • @jcoppens: the [`.image.load()`](https://www.pygame.org/docs/ref/image.html) function supports .png files – elegent Apr 03 '15 at 09:54
  • @elegent I know it *can* support them, but read here: https://www.pygame.org/docs/ref/image.html#pygame.image.load Which means that it is possible pygame was built without png support. The OP should do the test described to see if support is built in. – jcoppens Apr 03 '15 at 13:36
  • @jcoppens: Thanks for pointing that out! You are absolutely right. @Roman Formicola: try if `pygame.image.get_extended()` returns `true`, otherwise, as jcoppens already mentioned, your PyGame installation does not sport .png formats. – elegent Apr 03 '15 at 13:44

0 Answers0