user1452509
user1452509

Reputation: 97

Weird Pygame Error

I'm creating a game, and I've made a world map image using paint.NET. I saved it as a JPEG file and am trying to load and blit it to a Pygame frame. Here is my code:

    import pygame
    import sys
    from pygame.locals import *

    Surface = pygame.display.set_mode ((1000, 775)), 0, 32)
    pygame.display.set_caption ('World Map')
    white = (255, 255, 255)
    pygame.image.load ('WorldMap.jpg')
    while True:
        Surface.fill (white)
        WorldMap.blit(Surface, (900, 675))
        for event in pygame.event.get ():
            if event.type == QUIT:
                pygame.quit ()
                sys.exit(0)
         pygame.display.update()

My error is that it tells me that it cannot load WorldMap.jpg

Upvotes: 0

Views: 144

Answers (3)

pmoleri
pmoleri

Reputation: 4449

In the code you posted, the image isn't assigned to a variable and the blitting is backwards:

    pygame.image.load ('WorldMap.jpg')
    while True:
        Surface.fill (white)
        WorldMap.blit(Surface, (900, 675))

should be:

    WorldMap = pygame.image.load('WorldMap.jpg')
    while True:
        Surface.fill(white)
        Surface.blit(WorldMap, (900, 675))

Upvotes: 2

Mizipzor
Mizipzor

Reputation: 52381

Try specifying a full path to the jpg file.

If it still fails, please update your question to include the full error you get.

Upvotes: 0

Dan
Dan

Reputation: 4663

For whatever reason it isn't loading the image. Here are some steps you can take to attempt to resolve this issue:

  • Attempt to open the image in an external viewer. If you cannot view it it may be corrupt or have permissions issues.
  • Check the permissions settings on the image.
  • Make sure the image is in the same folder as the python script
  • Ensure the image is actually a jpeg image. Did you perhaps save it as a bitmap (BMP) but change the file extension to JPG without changing the format?

Beyond this I cannot be of much help without seeing the entire error and knowing what you found in each of these steps.

Upvotes: 0

Related Questions