Skip to main content

On Sale: GamesAssetsToolsTabletopComics
Indie game storeFree gamesFun gamesHorror games
Game developmentAssetsComics
SalesBundles
Jobs
TagsGame Engines

Sprite Layer Priority

A topic by Cattledog created Feb 07, 2021 Views: 722 Replies: 10
Viewing posts 1 to 8

I use a small plug by glaphen that this plugin seems to break.  All the plugin does is changes sprite layer priority depending on who is attacking by flipping a switch:

Spriteset_Battle.prototype.battleFieldDepthCompare = function(a, b) {
var priority = BattleManager.getSpritePriority();
if (a._battler && b._battler) {
if (!$gameSwitches.value(500)) {
if (a._battler.isActor() && b._battler.isEnemy()) return 1;
if (a._battler.isEnemy() && b._battler.isActor()) return -1;
} else {
if (a._battler.isActor() && b._battler.isEnemy()) return -1;
if (a._battler.isEnemy() && b._battler.isActor()) return 1;
}
}
if (a.z < b.z) return -1;
if (a.z > b.z) return 1;
if (a.y < b.y) return -1;
if (a.y > b.y) return 1;
return 0;
};

Any chance of a compatibility fix?

Developer

What's the exact error you get?

There is no error that is produced (i checked the console as well), the sprite priority no longer functions when having battlers overlap.    

With the plugin i posted above, you can dictate the battlers sprite priority.  It is functioning correctly in the left frame - battler on the left should have layer priority (JM_EarthboundBackgrounds disabled) and in the right frame ( with JM_EarthboundBackgrounds enabled), it no longer correctly takes sprite priority.  

Developer (1 edit)

Where do you call 

Spriteset_Battle.prototype.battleFieldDepthCompare

because it's not a default RMMV parameter, and that might be causing the error. My plugin overwrites

Spriteset_Battle.prototype.adjustSprite
Spriteset_Battle.prototype.updateZCoordinates

Now that I think about it, if that plugin overwrites updateZCoordinates, it would be wiped clean by my plugin, so try including that plugin after EarthboundBackgrounds and see what happens.


Basically: Flip the order of the 2 plugins and see if that fixes things.

Developer

Sidenote: The reason the plugin overwrites 

Spriteset_Battle.prototype.updateZCoordinates

is something about compatibility with Yanfly Battle Core. I might experiment later to see what exactly is going on, but it was replaced by a no-op...maybe it was messing with _back*Sprite which this plugin coerces. 

I should have mentioned earlier that I had flipped the plugin order to no avail.   I created a new project with the minimum amount of plugins as possible, it definitely does not like it if you place your plugin above the yanfly's battle engine core.

Developer

Do you know where 

Spriteset_Battle.prototype.battleFieldDepthCompare

is called in the other plugin? Yeah, my plugin specifically doesn't like being included before Battle Core because of the whole updateZCoordinates thing.

Not sure if this is what you are looking for, but found this in YEP_BattleEngine:

//=============================================================================
// Spriteset_Battle
//=============================================================================

Spriteset_Battle.prototype.isBusy = function() {
    return false;
};

Yanfly.BEC.Spriteset_Battle_update = Spriteset_Battle.prototype.update;
Spriteset_Battle.prototype.update = function() {
    Yanfly.BEC.Spriteset_Battle_update.call(this);
    this.updateZCoordinates();
};

Spriteset_Battle.prototype.updateZCoordinates = function() {
  if (Imported.YEP_ImprovedBattlebacks) {
    this.updateBattlebackGroupRemove();
  } else {
    this._battleField.removeChild(this._back1Sprite);
    this._battleField.removeChild(this._back2Sprite);
  }
  this._battleField.children.sort(this.battleFieldDepthCompare);
  if (Imported.YEP_ImprovedBattlebacks) {
    this.updateBattlebackGroupAdd();
  } else {
    this._battleField.addChildAt(this._back2Sprite, 0);
    this._battleField.addChildAt(this._back1Sprite, 0);
  }
};

Spriteset_Battle.prototype.battleFieldDepthCompare = function(a, b) {
    var priority = BattleManager.getSpritePriority();
    if (a._battler && b._battler && priority !== 0) {
      if (priority === 1) {
        if (a._battler.isActor() && b._battler.isEnemy()) return 1;
        if (a._battler.isEnemy() && b._battler.isActor()) return -1;
      } else if (priority === 2) {
        if (a._battler.isActor() && b._battler.isEnemy()) return -1;
        if (a._battler.isEnemy() && b._battler.isActor()) return 1;
      }
    }
    if (a.z < b.z) return -1;
    if (a.z > b.z) return 1;
    if (a.y < b.y) return -1;
    if (a.y > b.y) return 1;
    return 0;
};

Spriteset_Battle.prototype.isPopupPlaying = function() {
    return this.battlerSprites().some(function(sprite) {
        return sprite.isPopupPlaying();
    });
};

Yanfly.BEC.Spriteset_Battle_battlerSprites =
  Spriteset_Battle.prototype.battlerSprites;
Spriteset_Battle.prototype.battlerSprites = function() {
  var sprites = Yanfly.BEC.Spriteset_Battle_battlerSprites.call(this);
  var length = sprites.length;
  var result = [];
  for (var i = 0; i < length; ++i) {
    var sprite = sprites[i];
    if (!sprite) continue;
    if (!sprite._battler) continue;
    result.push(sprite);
  }
  return result;
};

Developer

Try this build: https://www.dropbox.com/s/06iaa12eqvo3odi/dist_20210303.zip?dl=0

updateZCoordinates now only calls the line this._battleField.children.sort(this.battleFieldDepthCompare); without the battleBack stuff, so this might work.

It appears to be working! Thank you so much! Makes me very happy to use this plugin in my project.  I had  an additional question - any terms of use?  I am assuming the backgrounds were ripped from EB?

Developer (2 edits)

Yeah the backgrounds that come with the plugin in a separate zip are all ripped from the EB ROM afaik, so try not to use those if publishing.

Feel free to keep me in the loop of any game you develop, whether free or commercial.