[Author Prev][Author Next][Thread Prev][Thread Next][Author Index][Thread Index]
[pygame] Pygame.init In Multiple Files
Hi! I'm working on a project involving multiple .py files, several of
which can write to the screen.
-worldsim_evergreen.py can run on its own, loading some JPGs and
displaying them as tiled graphics.
-world1_main.py is meant as a shell for the other one, adding an
interface and other features.
The problem is, world1_main crashes when I run it _a second time_ from
IDLE. I run it once, worldsim_evergreen loads its graphics, and
everything is fine. I quit normally (calling pygame.display.quit() to
close the graphics window) and run world1_main again. This time it has
worldsim load _some_ of the graphics, but then crash when it tries to
load some other graphics. worldsim is calling a class function,
World.LoadGraphicTiles():
def LoadGraphicTiles(self):
"""Load graphic tiles from "graphics" folder."""
global tilearr, GENERIC_OBJECT_IMAGE, GENERIC_PERSON_IMAGE
for x in range(NUM_TILES):
tilearr[x]=pygame.image.load(
os.path.join("graphics",(str(x) + ".jpg")) ).convert()
GENERIC_OBJECT_IMAGE = pygame.image.load(
os.path.join("graphics",GENERIC_OBJECT_IMAGE) ).convert()
GENERIC_PERSON_IMAGE = pygame.image.load(
os.path.join("graphics",GENERIC_PERSON_IMAGE) ).convert()
It crashes when it tries to load GENERIC_OBJECT_IMAGE. That and
GENERIC_PERSON_IMAGE are defined at the top of worldsim_evergreen.py as
strings giving file names. But it doesn't crash the first time I run it
from IDLE without quitting and re-opening the file!
In worldsim_evergreen.py is this code:
import pygame ## Pygame
pygame.init()
And in world1_main.py is:
import pygame
pygame.init()
screen = pygame.display.set_mode([1024,768])
So the shell program and its "worldsim" both initialize pygame, which
seems to be necessary for worldsim to load its graphics.
Any idea what's going on?
Kris Schnee
AI Tinkerer