Hi guys, im developing a game that involves spawning a large amount of entities at once, my default fps is 60, but when i use more fps it seems as if the game were to move faster, is that something common in processing ? and is there a way make it not happen while still maintaining a high fps?
Second thing is that my fps gradually drops from 60 to around 30-25 when the game reaches it entity spawn peak (at the end game), i was told there might be some ways to be able to spawn a lot of entities but somehow get much less lag , i would like to learn more about how to this, thanks in advanced!
Btw my code is thousands of lines so i can’t share all of it at this point but if needed i can share the parts that are relevant, i didn’t upload any because i figured the question is general and can be answered without the code.
For consistent motion independent of the frame rate, base your motion on the real world time. Get the millis() each frame and subtract from the previous frame to find the change in time (delta time or ‘dt’) then move your objects at speed * dt.
If you have a large amount of work to do, break it into smaller chunks and do a little bit each frame. If the player is entering a room with hundreds of enemies, create them gradually as the player approaches rather than the instant they enter the room. Alternatively use a separate compute thread to create the enemies, but that brings its own set of complexities to synchronize with the rendering thread.
Adding to @scudly’s point about deltaTime, I found this video by Jonas Tyroller
particularly enlightening. Though it is not specifically about Processing, the concepts explained apply broadly to any game which deals with time and movement.