What is the most effective and fastest way to switch objects group layer like this:
When (for example) an object1 is moved on the screen and it should be shown before another object2 (when it’s y-value on a map is bigger then y from object2 for example) I want to switch the objects group index position, so the object1 is shown in front of the object2. Because there are a lot of other moving objects on the screen I only want to switch the index for this two objects and can’t work with object1:toFront() here.
Is there a “Best Way” to do this kind of object group switching? This is needed in all kind of games, like for example when characters are moving on a map and they have to appear in front of enemies or buildings or stuff, when their y-value is bigger then the enemies, building… y-value.
What is the fastest (and easiest) way to switch objects in groups to make this switching work fast with a LOT of different objects?
Any help welcome!