0

So basically, its all well and good when I have it at this stage:

import pygame
from pygame.locals import *

pygame.init()

screen_width = 1000
screen_height = 1000

screen = pygame.display.set_mode((screen_width, screen_height))
pygame.display.set_caption('Platformer')






run = True
while run:

    for event in pygame.event.get():
        if event.type == pygame.QUIT:
            run = False

pygame.quit()

but as soon as i add something like this:

import pygame
from pygame.locals import *

pygame.init()

screen_width = 1000
screen_height = 1000

screen = pygame.display.set_mode((screen_width, screen_height))
pygame.display.set_caption('Platformer')

sun_img = pygame.image.load('img/sun.png')
bg_img = pygame.image.load('img/sky.png')







run = True
while run:
    

    for event in pygame.event.get():
        if event.type == pygame.QUIT:
            run = False





pygame.quit()

it just opens and closes immediately. Im a huge novice with code and am just having some fun for now but this issue is really annoying and I would appreciate any help I could get!

  • 1
    You don't get any errors? It just returns/exits without doing anything or printing anything to the console? And you're just adding those two lines that each load an image? The obvious problem would be that those image files aren't being found, possibly because the paths aren't right given the current working directory. But if that were the case, you should be getting an error message when Python tries to load the first image. - Try providing the full paths of the image files just to rule out any current directory issues. – CryptoFool Mar 07 '21 at 06:46
  • ...I tried running your code, and not having your images, I get a `FileNotFoundError: No such file or directory.` in my output window in PyCharm. If you haven't found it yet, look carefully to make sure you aren't getting a similar error. - Other than getting that error, I otherwise get the behavior you describe. The PyGame window comes up, and then quickly goes away. I bet this is your issue. – CryptoFool Mar 07 '21 at 06:49
  • `pygame.display.update()` is also missing – CopyrightC Mar 07 '21 at 08:14

0 Answers0