r/learnpython • u/Euphoric_Pop_1149 • 14d ago
How to run a function in paralell to a game loop?
not sure if its the right sub but nevermind.
My pygame game would need to have the main menu kept animated (not frozen) while a world generating function runs before switching to a different loop.
My architecture is right now this:
main.py: main menu loop, menu buttons
game.py: game loop
in main.py i call the runGame() function from game.py, which executes my game stuff. runGame() sets up some global objects (Player, World, campos) that are shared between files from game.py.
The worldgen function has its own file and accessible from any file as it has no dependencies. It takes ~2-4 seconds to run so its not that huge yet, but it isn't pretty as of now.
What is a good way to achive this (or similar) results?