Hi guys. I’m making Vampire Survivors clone as my first project in Defold.
Everything works quite well, even with 1000 enemies rushing toward the player, as long as Vsync is disabled.
Let me share some more about the scene and settings:
- All 1000 enemies have one animated sprite, dynamic collision object and script, that pushes them toward the player.
- There are 18 drawcalls in each frame.
- Physics engine is 2D type, with fixed timestep set to 30.
- Apart from enemies, there are GUI, tiled map with 6000 tiles and the player.
- Resolution: 1600x900, framerate of my display is 60Hz.
And the illustrative graphic:
I had issue with ustable FPS and have been exprimenting for quite long time with different types of collision objects (kinematic/trigger) and handling collsiion in lua, various physic timestamps etc, however nothing really helped, I couldn’t achieve stable 60 FPS for more that 100 enemies touching each other.
I decided to untick the Vsync in Display setting and I was stunned… 500 fps (with min: 400, max 800) just happend with basic dynamic collisions. It more than enough for me, however it’s strange that with Vsync enabled the FPS is unstable.
Summary of different settings and achieved FPS:
- Update freq: 0, Vsyns: DISABLED – FPS: min: 400, avg 560, max 800.
- Update freq: 30, Vsyns: DISABLED – FPS: min: 29.8, avg 30.0, max 30.1.
- Update freq: 60, Vsyns: DISABLED – FPS: min: 59.7, avg 60.0, max 60.3.
- Update freq: 120, Vsyns: DISABLED – FPS: min: 105, avg 110, max 115.
- Update freq: 0, Vsyns: ENABLED – FPS: min: 27, avg 59, max 64.
- Update freq: 30, Vsyns: ENABLED – FPS: min: 29.9, avg 30.0, max 30.01.
- Update freq: 60, Vsyns: ENABLED – FPS: min: 59.2, avg 60.0, max 60.5.
- Update freq: 120, Vsyns: ENABLED – FPS: min: 13, avg 58, max 63.
As you can see above, the theoretical max FPS is quite high and stable. Also it is possible to maintain 60 FPS with update frequency set to 60 and no Vsync.
Is anybody have clue why there is sudden drop in stability, when Vsync is enabled and update frequency is higher than display framerate? The FPS drops are still present even when the amount of enemies is reduced to 250.