0

This is my first time posting on Stack Overflow so please let me know if I could be doing anything better for asking my question!

Here is the tutorial I am following timestamped to about where I was. I am using VSCode Python, and Pygame. https://youtu.be/UZg49z76cLw?t=1138

I have the file in the directory specified and I have made sure it is named correctly by copy-pasting it.

Whenever I run my code, the bg_surface does not show up on my screen. Before it said that it didn't exist, but I have put the full file address in and it stopped doing that, but still won't display the actual image. I would also like to get away from using the full file path as I won't be able to send it... import pygame, sys

pygame.init()#initiating pygame
screen = pygame.display.set_mode((576,1024))#Set canvas size
clock = pygame.time.Clock()

bg_surface = pygame.image.load('C:\\Users\\{my_name}\\MyPythonScripts\\Flapp\\assets\\background-day.png')
bg_surface = pygame.transform.scale2x(bg_surface)

while True:
    for event in pygame.event.get():
        if event.type == pygame.QUIT:
            pygame.quit()#Ends the game
            sys.exit()#ends the program
    
    screen.blit(bg_surface,(0,0))#Blit puts a surface on another surface

    pygame.display.update#Update screen
    clock.tick(120)#Set framerate

Things I have tried:

bg_surface = pygame.image.load('C:\\Users\\{my_name}\\MyPythonScripts\\Flapp\\assets\\background-day.png')
bg_surface = pygame.image.load('assets\\background-day.png')
bg_surface = pygame.image.load('assets/background-day.png')
bg_surface = pygame.image.load(r'assets/background-day.png')
bg_surface = pygame.image.load(r'assets\background-day.png')
bg_surface = pygame.image.load('assets\background-day.png')

And a lot of variations like those. Bonus points if you can tell me why I get:

Exception has occurred: SystemExit
  File "C:\Users\Corbin\MyPythonScripts\Flapp\flapp.py", line 14, in <module>
    sys.exit()#ends the program

When I close the program... Thanks!

  • 6
    You're not calling `pygame.display.update`, you're just referencing it. To call it you need parentheses: `pygame.display.update()`. And you get the `SystemExit` exception because you call [`sys.exit()`](https://docs.python.org/3/library/sys.html#sys.exit). – Matthias Sep 24 '20 at 15:55
  • You solved my issue with the background! You rock!! And should I just be ok with that error popping up? the tutorial tells me that is what I need to put in there... – Corbin Barrett Sep 24 '20 at 16:25
  • The `SystemExit` exception is nothing to worry about, it's due to the exception handling in your IDE. – import random Sep 25 '20 at 01:30

1 Answers1

0

Corbin, you haven't put parenthesis at the end of pygame.display.update. It should rather be pygame.display.update(). That's when you'll be able to get your background image.