Speeding up Performance on Mobile Devices

I making a game involving objects destroying orbiting objects when they crash into each other. It works well with my laptop, desktop, and chromebook, but is very laggy on iPhone and Android phones. I am trying everything I can to boost performance, but nothing I do seems to make a difference. Can anyone help with this?

Can you share a link to the project? Without knowing what is used, it’s hard to give specific advice.

Have you read the performance section of the User Manual?

Here’s the project: https://playcanvas.com/project/457023/overview/new-3

Tried it on my S7 and performance seemed to be fine.

While there a quite a few little optimisations you can do, the biggest problem that you would have is that mobiles don’t really handle a lot of physics objects very well. For what I can see in the project, you might be a lot better off using simple sphere to sphere checks instead of using ammo.js.

How would I do this?

Keep an array of the satellite game objects and just do sphere to sphere checks on them every frame.

e.g (untested code)

var entityCollides = function(left, right) {
    // Do sphere sphere check
};

var entityArray = [];

// Add the entity to the array when they are spawned

var i = 0;
var j = 0;
var collided = false;
var tempEntity = null;

while(i < entityArray.length) {
    j = i + 1;
    while(j < entityArray.length) {
        if (entityCollides(entityArray[i], entityArray[j])) {
            // Insert some code to destroy the entity

            // Remove the entity reference from the script
            entityArray[j] = entityArray[entityArray.length - 1];
            entityArray.pop();

            collided = true;
        } else {
            j += 1;
        }

        if (collided) {
            // Insert some code to destroy the entity

            // Remove the entity reference from the script
            entityArray[i] = entityArray[entityArray.length - 1];
            entityArray.pop();
        } else {
            i += 1
        }
    }
}

I would also suggest that you use entity pools instead of cloning and destroying entities. It’s a lot cheaper at runtime and will help with frame drops from the garbage collector.

How would I use entity pools? I’m still kinda new to this program

Object pools is a generic technique that works across most engines. Basically, at the start of the app, you create X number clones/instances of the object that you want to pool and add them to a container.

When you want to add one to the world, you remove it from the container and enable/parent/attach to the scene. When you no longer want it to be in the scene (e.g it explodes and you want to remove it from the world), you disable it and add it back to the container.

This talk explains the concept quite well (despite being a bit long): https://www.youtube.com/watch?v=RWmzxyMf2cE&index=11&list=PLnme6Xn4RVFAKMMmL22K3Si4Cj5aZmOMO

1 Like

That is an amazing talk. I’m not sure I learned anything through the “arrgh’s” and “ayes,” but I sure enjoyed it…

Ok so I figured out the way to do pools, and I figured out that the shadows were really stunting performance. A new problem I have now that I did not have previously is that some particle systems are stunting perfomance. And I am still unsure of how to do a sphere check.