Change Battlers' Sprite Z order?

Isabella Ava

Veteran
Veteran
Joined
Sep 13, 2016
Messages
635
Reaction score
756
First Language
English
Hi guys,
I tried to change battlers' Z order with this code but it doesn't work:
I think i sorted the wrong array.. perhaps?
Can someone help me, plz (っ- ‸ – ς)
Code:
//changeZ
BattleManager.cChangeZ = function(name, actionArgs) {
    var movers = this.makeActionTargets(name);
    if (movers.length < 1) return true;
    var cZ = parseInt(actionArgs[0]);
    //check to see if mover is Actor or Enemy
    //console.log(movers);
    var actors = SceneManager._scene._spriteset._actorSprites;
    var enemies = SceneManager._scene._spriteset._enemySprites;
    for(var i = 0; i < movers.length; i++) {
        if (movers[i].isActor()) {
            actors.some(function(actor) {
                if (actor._actor._actorId == movers[i]._actorId) {
                    actor.z = cZ; return true;
                } else {return false;}
            });
        } else {
            enemies.some(function(enemy) {
                if (enemy._enemy._enemyId == movers[i]._enemyId && enemy._enemy._letter.trim() == movers[i]._letter.trim()) {
                    enemy.z = cZ; return true;
                } else {return false;}
            });
        }
    }
    
    //REFRESH
    SceneManager._scene._spriteset.battlerSprites().sort(function(a,b) {
        a.z = a.z || 1;
        b.z = b.z || 1;
        return a.z - b.z;
    });
    //console.log(SceneManager._scene._spriteset.battlerSprites());
    
    return true;
};
 

Poryg

Dark Lord of the Castle of Javascreeps
Veteran
Joined
Mar 23, 2017
Messages
4,125
Reaction score
10,639
First Language
Czech
Primarily Uses
RMMV
You tried to sort the correct array I think. You just didn't sort it the correct way.
Code:
function compare(a, b) {
  if (a is less than b by some ordering criterion) {
    return -1;
  }
  if (a is greater than b by the ordering criterion) {
    return 1;
  }
So what you should have returned is not a.z - b.z, but
a.z >= b.z ? 1 : -1
 

Users Who Are Viewing This Thread (Users: 0, Guests: 1)

Latest Threads

Latest Posts

Latest Profile Posts

How many parameters is 'too many'??
Yay, now back in action Happy Christmas time, coming back!






Back in action to develop the indie game that has been long overdue... Final Fallacy. A game that keeps on giving! The development never ends as the developer thinks to be the smart cookie by coming back and beginning by saying... "Oh bother, this indie game has been long overdue..." How could one resist such? No-one c
So I was playing with filters and this looked interesting...

Versus the normal look...

Kind of gives a very different feel. :LZSexcite:
To whom ever person or persons who re-did the DS/DS+ asset packs for MV (as in, they are all 48x48, and not just x2 the pixel scale) .... THANK-YOU!!!!!!!!! XwwwwX

Forum statistics

Threads
105,849
Messages
1,016,981
Members
137,563
Latest member
cexojow
Top