Pygame.error:video System Not Initialized
Solution 1:
Without running your code or having a stack trace of where the problem happens, we need to debug the code for you first. So it would be beneficial to add a full stack trace to your questions. I'm pretty confident however that there's two issues that you should work out.
pygame.display.update()
should be correctly indented to be in the while
loop of your main game event loop. Secondly, the pygame.init()
should be run before any other initialization (or at least so I've been taught over the years and every example points to)
Try this out, I think it solves your problem:
# Pygame development 4# Focus on making code object oriented# Introduce classes and objects into our code# Gain access to the pygame libraryimport pygame
pygame.init()
# Size of the screen
SCREEN_TITLE = 'Crossy RPG'
SCREEN_WIDTH = 500
SCREEN_HEIGHT = 500# Colors according to RGB codes
WHITE_COLOR = (255, 255, 255)
BLACK_COLOR = (0, 0 , 0)
# Clock used to update game events and frames
clock = pygame.time.Clock()
pygame.font.init()
font = pygame.font.SysFont('comicsans', 75)
classGame:
# Typical rate of 60, equivalent to fps
TICK_RATE = 60# Initializer for the game class to set up the width, height, and titledef__init__(self, title, width, height):
self.title = title
self.width = width
self.height = height
# Create the window of specified size in white to display the game
self.game_screen = pygame.display.set_mode((width, height))
# Set the game window color to white
self.game_screen.fill(WHITE_COLOR)
pygame.display.set_caption(title)
defrun_game_loop(self):
is_game_over = False# Main game loop, used to update all gameplay suh as movement, check, and graphics# Runs unit is_game_over = Truewhilenot is_game_over:
# A loop to get a;l of the events occuring at any given time# Events are most often mouse movement, mouse and button clicks, or eit eventsfor event in pygame.event.get():
# If we have a quite type event(exit out) then exit out of the game loopif event.type == pygame.QUIT:
is_game_over = Trueprint(event)
# Update all game graphics
pygame.display.update()
# Tick the clock to update everything within the game
clock.tick(self.TICK_RATE)
new_game = Game(SCREEN_TITLE, SCREEN_WIDTH, SCREEN_HEIGHT)
new_game.run_game_loop()
pygame.quit()
This also seams to be a school assignment and not a online course (but I might be wrong here), never the less I'll leave this piece of advice if I'm right. I strongly suggest that if you bump into problems, ask your teacher for guidance. As there's always a reason for teachers giving you a challenge/problem to solve. It teaches you the latest techniques you've learned in class, and if you can't solve the problem with the tools that you've been given - you've most likely haven't learned the fundamentals that has been taught out - and you should really re-do some steps.
Post a Comment for "Pygame.error:video System Not Initialized"