JohnLavender474 / Megaman-Maverick

Megaman fan game built using LibGDX and a custom game engine
3 stars 0 forks source link

Blocks do not always spawn #1

Open JohnLavender474 opened 2 months ago

JohnLavender474 commented 2 months ago

Although it is rare, there are instances where blocks (or other entities, but primarily blocks) do not always spawn. This seems to be caused by a race condition between when the spawner indicates that it has "just entered the camera bounds" and when the existing block is culled. In other words, in these instances, the spawner checks if it has "just entered the camera bounds", determines that it has done such but its owned entity is already spawned so it does nothing, and then the entity (in this case the block) is culled afterwards because its cull timer runs out.

To combat against this condition from occuring, the render method in MegaLevelScreen has been changed so that the SpawnsManager runs twice, once before the GameEngine is updated and once afterwards.

See the following: Screenshot from 2024-09-12 16-56-18

The issue seems to have disappeared, but if it reappears again, it might be a good idea to eliminate culling for blocks (and other such vital entities) entirely. Although doing so would increase compute time since every block would have to be processed in the world (rather than just those on screen), this is far preferable to the alternative where blocks do not always spawn. Screenshot from 2024-09-12 16-58-14