.
You’re creating a file for every ball every time you release the spacebar?
FIlesystem I/O is very slow and it blocks the thread. It’s bad enough to do it on the main thread in the middle of gameplay, but to write 100 files in the middle of a frame? I’m not sure what you are expecting, but writing that many files is going to take a very long time relative to a normal frame of a game. And while it is writing these files, the game will be effectively frozen until it is complete.
To fix this, don’t do blocking file I/O on the main thread in the middle of user interaction. What exactly are you trying to accomplish here?
1 Like