Support Me on Patreon

Thursday, July 11, 2019

Can't have lag from adding objects if you don't add objects.

There are many sources of lag in games. Most notable is skeletal animations. Loops, print statements, and loops with print statements can also add up. One thing most new developers don't notice, is that adding and removing objects can get heavy for lots of objects. Sometimes you have to add objects, like critters and bombs.

Of course, some objects warrant particle effects or sound effects when they hit. Objects, like bombs, don't usually stick around to play audio or particles.Removing objects early can truncate these effects, and programming a wait timer is something I'm too lazy to do.

You could always add the effect or sound objects and remove them after, but let's keep them in the scene. Better yet, add about 5-10 of these setups to the scene; inactive. Make a global variable in a pre-load script to keep track of which FX setup you are going to use. Before the attack/grenade/ammo is removed, move the current FX setup to the current object and activate it. Leave it there and update the current FX variable for the next FX setup.

By the time you loop through the setups, the first one should be done and inactive. Keep moving and using the setups as needed. Shuffling objects or setups can help for anything and reduces load since you don't keep adding these objects. You could even shuffle raindrops around the player for the illusion of rain if particle effects are unavailable or unusable for rain (some don't handle collisions and rain could clip indoors).

This option works for any kind of visual effect, from gunshots to bullet holes. Keep several in the scene and move them around / make them visible/active as needed.

No comments:

Post a Comment