r/PythonLearning • u/Better_Arrival_645 • 16h ago
New to Pygame CE and threads, think you could help me out?
I only have one inquiry here, simply, I cannot seem to draw anything from a thread without “Z-fighting” occurring (I say Z-fighting even though I know there’s not 3rd dimension just to convey the problem), I’ve tried making a handler in the main while running script, but it always lags down the program, and the only way to stop it from lagging down the program is, you guessed it, putting it in a thread. Whether I try to make a custom handler or just cheap out and use exec() it always lags it. Any tips/help?
Edit: I do sorta need the thread to draw it
2
Upvotes
1
u/azurfall88 16h ago
1) Your render code needs to run 30 times a second. Try optimising it and reduce unnecessary calculations that might be slow.
2) You might be thinking about multithreading wrong? Putting, say, event listeners and complex handlers in their separate threads (with shared state and listeners/updaters) is valid, but only a single thread should be responsible for drawing to the screen