Hello, does anyone know what’s better for performance, a single array controlling most events or multiple arrays for each different event? In a game I’m making I have 2 arrays, one controlling the fire and one controlling the particles (falling debris etc), here’s an example of the code so far:
Fire array
for (var XXX=0; XXX<array_fire.length; XXX++)
{
if (array_fire[XXX].removal >= 40)
{
duplicates.removeChild(array_fire[XXX]);
array_fire.splice(XXX,1);
}
else
{
array_fire[XXX].y -= 2;
array_fire[XXX].removal++;
}
}
Particle array
for (var XXX=0; XXX<array_physics.length; XXX++)
{
array_physics[XXX].y += array_physics[XXX].y_speed / 10;
array_physics[XXX].x += array_physics[XXX].x_speed;
if (array_physics[XXX].y <= 1000)
{
duplicates.removeChild(array_physics[XXX]);
array_physics.splice(XXX,1);
}
}
As far as I’m aware a single array would be better to minimize memory usage but I don’t know if a single array is better to ensure the best performance.
Thank you for reading and thanks for your input