1

Imports

#Imports
import pygame, sys, time, random
from pygame.locals import *

Display

pygame.init() #initializes pygame window
pygame.display.set_caption('Parkour') #titlebar caption

Bg=pygame.display.set_mode((800,600),0,32) #sets main surface

"""--------------------------------------------------------------------------"""

Event loop

gameActive = True
while gameActive:
    #print (event)
    for event in pygame.event.get():
        if event.type == pygame.QUIT:
            gameActive = False     
pygame.quit()
quit()

Background (ISSUE) Yeah I'm a beginner, but shouldn't this fill the screen then update it? Bg is true so it should constantly run right?

#Background
Bg = True
while Bg:
    screen.fill((0,0,255))
    pygame.display.flip()
XenElixer
  • 11
  • 3

1 Answers1

1

Furthermore the variable Bg is the Surface which is associated to the window:

Bg=pygame.display.set_mode((800,600),0,32) #sets main surface

Do not use the same variable name for a boolean state:

Bg = True

I recommend to change the name of the display surface (e.g. screen), because you've used this name in screen.fill((0,0,255)), too:

screen = pygame.display.set_mode((800,600),0,32) #sets main surface

Of course you have fill the background and to update the display in the main application loop. The main application has to

  • handle the events

  • clear the display

  • draw the scene

  • update the display

continuously in every frame.

e.g.:

#Imports
import pygame, sys, time, random
from pygame.locals import *

pygame.init() #initializes pygame window
pygame.display.set_caption('Parkour') #titlebar caption

screen = pygame.display.set_mode((800,600),0,32) #sets main surface

# main application loop
gameActive = True
while gameActive:

    # handle the events in the event loop
    for event in pygame.event.get():
        if event.type == pygame.QUIT:
            gameActive = False 

    # clear the display
    screen.fill((0,0,255))

    # draw the scene
    # [...] draw things here

    # update the display
    pygame.display.flip()     
Rabbid76
  • 202,892
  • 27
  • 131
  • 174