Teed Ferguson
Teed Ferguson

Reputation: 317

Image not fitting

I am trying to load an image as a background in pygame. I have done this before, and followed the same process, but with my latest game it is showing up wonky and I'm not sure why... My original image (below) is 1280x645 and I use this code to load/display it:

import pygame
pygame.init()

win = pygame.display.set_mode((1280,645))    
bg = pygame.image.load('CheeseFarm_Background.png')

win.blit(bg, (0,0))

Original image

But, when I run it, it looks like this:

What I see

Ideas what I am doing wrong?

Upvotes: 2

Views: 64

Answers (1)

Kingsley
Kingsley

Reputation: 14926

There's not really enough code to say what could be the problem. The image in the post works fine for me. Obviously your code has no event loop, so probably the window closes immediately. I expect the code was omitted to make the question smaller.

The code below opens a window and displays the bitmap from the question correctly.

import pygame

### initialisation
pygame.init()
win = pygame.display.set_mode((1280,645))    
bg = pygame.image.load('dairy_farm.png')


### Main Loop
clock = pygame.time.Clock()
done = False
while not done:

    # Handle user-input
    for event in pygame.event.get():
        if ( event.type == pygame.QUIT ):
            done = True
        elif ( event.type == pygame.MOUSEBUTTONUP ):
            # On mouse-click
            mouse = event.pos
            print( "Click at " + str( mouse ) )

    # Update the window, but not more than 60fps
    win.blit(bg, (0,0))
    pygame.display.flip()

    # Clamp FPS
    clock.tick_busy_loop(60)

pygame.quit()

Upvotes: 1

Related Questions