user3024479
user3024479

Reputation: 1

Loading images in Pygame

First: I am completely new to programming and I just started pygame. Everything just went fine so far, untill I was trying to load a background image. Here is my code: Any help would be great! I don't really see the problem though. EDIT: I am using Mac OSX.

import pygame
import os
import sys

pygame.init()

screen = pygame.display.set_mode((800, 500))
caption = pygame.display.set_caption("Space Game") 
done = False
y = 220
x = 10
delay = 0
circles = []

screen = pygame.display.get_surface()
background = os.path.join("/Users/user/Desktop/proj/space-game/realBackground.png")
background_surface = pygame.image.load(background).convert()
screen.blit(background_surface, (800, 220))
pygame.display.update()

clock = pygame.time.Clock()

while not done:
        for event in pygame.event.get():
                if event.type == pygame.QUIT:
                        done = True

        pressed = pygame.key.get_pressed()
        if pressed[pygame.K_UP]: y -= 10
        if pressed[pygame.K_DOWN]: y += 10

        screen.fill((0, 0, 0))
        color = (0, 128, 255)
        pygame.draw.rect(screen, color, pygame.Rect(x, y, 60, 60))
        delay -= 1

        if pressed[pygame.K_SPACE]:
                if delay <= 0:
                        delay = 30
                        circles.append([70, y + 30])

        for i in range(0, len(circles)):
                circles[i][0] += 5
                pygame.draw.circle(screen, (0,0,255), (circles[i][0], circles[i][1]), 15, 1)

        pygame.display.flip()
        clock.tick(60)

Upvotes: 0

Views: 4095

Answers (3)

guacaplush.y
guacaplush.y

Reputation: 3

I think you can't use .png, you have to use .bmp

Upvotes: 0

Hyungjun
Hyungjun

Reputation: 65

You can always try to load a .bmp file instead of a .png.

bmp. stands for bitmap image. You can safely convert png to bmp with a few websites. I used this link to convert mine. Hope this might help.

HJ

Upvotes: 1

Rusty Rob
Rusty Rob

Reputation: 17173

try adding the line screen.blit(background_surface, (800, 220)) right after screen.fill((0, 0, 0))

It appears you're filling over the background in the while loop.

EDIT: here is a screenshot of it working (note changes circled in red)

screen shot

Upvotes: 1

Related Questions