MZ Need help working on a custom enemy collapse fade change.

I'm making adjustments to the collapse for enemies, but i'm trying to do something a bit different.
I'm trying to replace opacity with brightness, and rather than fade out the monster, i want the monster to slowly turn black while a blend mode is put into effect.
This is what i have.. and i keep thinking there must be a way.
Code:
Sprite_Enemy.prototype.startCollapse = function() {
    this._effectDuration = 29;
    this._appeared = false;
};

Sprite_Enemy.prototype.updateCollapse = function() {
    this.setBrightness *= this._effectDuration / (this._effectDuration - 1);
    this.blendMode = 1;
};
I figure i'm going about it wrong.. everything i've tried just gives me errors or makes the monster go instantly black.
everything i've tried just gives me errors or
That's what happens if you guess with code: programming needs a methodical and precise approach.
  • setBrightness does not exist on the core Sprite_Enemy, and if it did then based on that name I'd expect it to be a function ("do a thing"), not a value ("store a thing").

  • Your formula is incorrect: the denominator should be +1, not -1. To see why, consider a few _effectDuration values, e.g. 10 or 1: what's the result?
Suggestion (untested):
JavaScript:
Sprite_Enemy.prototype.updateCollapse = function() {
  const d = this._effectDuration;
  if (!this._colorFilter)  // color filter uses lazy-init
    this._createColorFilter();
  this._colorFilter.uniforms.brightness *= d / (d + 1);  // linear dim
  this.blendMode = 1;  // additive blend mode
};
(Enemy sprites don't usually change their brightness, so more code may be necessary to catch all cases, e.g. if the enemy is revived.)

I suggest you also add a header to the top of the plugin, e.g.
JavaScript:
/*:
 * @target MZ
 * @plugindesc A different collapse effect!
 * @author author
 * @url https://forums.rpgmakerweb.com/threads/176841/
 * @help Terms of use, helpful info, etc.
 */
The @target MZ directive suppresses the "this plugin may not be written for MZ" warning in the Plugin Manager. The rest is just nice to have~
That's what happens if you guess with code: programming needs a methodical and precise approach.
  • setBrightness does not exist on the core Sprite_Enemy, and if it did then based on that name I'd expect it to be a function ("do a thing"), not a value ("store a thing").

  • Your formula is incorrect: the denominator should be +1, not -1. To see why, consider a few _effectDuration values, e.g. 10 or 1: what's the result?
Suggestion (untested):
JavaScript:
Sprite_Enemy.prototype.updateCollapse = function() {
  const d = this._effectDuration;
  if (!this._colorFilter)  // color filter uses lazy-init
    this._createColorFilter();
  this._colorFilter.uniforms.brightness *= d / (d + 1);  // linear dim
  this.blendMode = 1;  // additive blend mode
};
(Enemy sprites don't usually change their brightness, so more code may be necessary to catch all cases, e.g. if the enemy is revived.)

I suggest you also add a header to the top of the plugin, e.g.
JavaScript:
/*:
 * @target MZ
 * @plugindesc A different collapse effect!
 * @author author
 * @url https://forums.rpgmakerweb.com/threads/176841/
 * @help Terms of use, helpful info, etc.
 */
The @target MZ directive suppresses the "this plugin may not be written for MZ" warning in the Plugin Manager. The rest is just nice to have~
I was trying to use minus thinking it'd start from 255 and minus it down to zero or something.. i don't know how this stuff works.. i'm not a coder, but i hate asking for plugins.. i try my hardest to figure things out on my own..
Also, there's a reason there's no header.. it's not on it's own.. i have several things in a single plugin doing different things separately. I like keeping things more organized, rather than having these little plugins cluttering the list for every little thing i'm changing.
Spoiler: This is several modifications to different things
Code:
/*:
 * @target MZ
 * @plugindesc adds many needed customizations to project.
 */

//Actor Command adjustments
(alias => {
  Scene_Battle.prototype.actorCommandWindowRect = function() {
    const rect = alias.apply(this, arguments);
    //rect.height = 216;
    //rect.width = 192;
    rect.x = 312;
    rect.y = 517;
    return rect;
  };
})(Scene_Battle.prototype.actorCommandWindowRect);

//Party Command adjustments
(alias => {
  Scene_Battle.prototype.partyCommandWindowRect = function() {
    const rect = alias.apply(this, arguments);
    //rect.height = 216;
    //rect.width = 192;
    rect.x = 312;
    rect.y = 517;
    return rect;
  };
})(Scene_Battle.prototype.actorCommandWindowRect);

//Sets Battle background to scale of screen
Sprite_Battleback.prototype.adjustPosition = function() {
    this.width = Graphics.width;
    this.height = Graphics.height;
    this.x = 0;
    if ($gameSystem.isSideView()) {
        this.y = 0;
    }
    const ratioX = this.width / this.bitmap.width;
    const ratioY = this.height / this.bitmap.height;
    const scale = Math.max(ratioX, ratioY, 1.0);
    this.scale.x = scale;
    this.scale.y = scale;
};

//Set's battler speed
Sprite_Actor.prototype.motionSpeed = function() {
    return 7;  // default 12
};

//Removes rectangles in menus
Window_Selectable.prototype.drawItemBackground = function(index) {
};

//Custom popup font size!
Sprite_Damage.prototype.fontSize = function() {
  return $gameSystem.mainFontSize();  // <- edit this line
};

//Change options window position and size
Scene_Options.prototype.optionsWindowRect = function() {
    const n = Math.min(this.maxCommands(), this.maxVisibleCommands());
    const ww = 500;
    const wh = 400;
    const wx = (Graphics.boxWidth - ww) / 2;
    const wy = (Graphics.boxHeight - wh) / 2;
    return new Rectangle(wx, wy, ww, wh);
};

//Adjust enemy collapse effect
Sprite_Enemy.prototype.startCollapse = function() {
    this._effectDuration = 29;
    this._appeared = false;
};
Sprite_Enemy.prototype.updateCollapse = function() {
    this.opacity *= this._effectDuration / (this._effectDuration + 1);
    this.setColorTone([89, 0, 71, 255]);
    this.blendMode = 1;
    //this.setBlendColor([0, 0, 0, 255]);
};

//Weapons animation adjustments
Sprite_Weapon.prototype.updateFrame = function() {
    if (this._weaponImageId > 0) {
        const index = (this._weaponImageId - 1) % 12;
        const w = 96;
        const h = 96;
        const sx = (Math.floor(index / 6) * 3 + this._pattern) * w;
        const sy = Math.floor(index % 6) * h;
        this.setFrame(sx, sy, w, h);
    } else {
        this.setFrame(0, 0, 0, 0);
    }
};
Sprite_Weapon.prototype.initMembers = function() {
    this._weaponImageId = 0;
    this._animationCount = 0;
    this._pattern = 0;
    this.anchor.x = 0.5;
    this.anchor.y = 0.7;
    this.scale.x *= 3;
    this.scale.y *= 3;
    this.x = -16;
    this.y = -32;
};

Sprite_Weapon.prototype.animationWait = function() {
    return 8;
};
I didn't see a point in a bunch of tiny plugins cluttering things.
Thankfully though, they don't interfere with each other.
And that which you sent works.
I was replicating some old snes RPG Death animations by way of this.
The way the snes works, is it would use something similar to blend mode 1 and rather than turning something transarent, it'd just slowly turn it black.. and because of how the hardware does transparencies it gives a unique look... doing it with just turning something totally transparent looks a bit different.
Turning it black with the blend 1 replicates this effect perfectly.
I just wanted to replicate how monsters fade out in RPG Tsukuru Super Dante on the super famicom/nintendo.
And that which you sent works.
Great! In case your enemies revive, you could try adding this patch too (untested):
JavaScript:
;(alias => {
  Sprite_Enemy.prototype.revertToNormal = function() {
    alias.apply(this, arguments);
    if (this._colorFilter)
      this._colorFilter.setBrightness(255);
  };
})(Sprite_Enemy.prototype.revertToNormal);
I.e. "reset brightness whenever a new effect starts".

I was trying to use minus thinking it'd start from 255 and minus it down to zero or something..
Note that the core scripts have a plus there, which normally causes the opacity to fade out, i.e. "minus it down to zero".

An expression in the form A *= B means "multiply A by B (and store the result in A)". For a decrease, you would expect to be multiplying by a value smaller than 1. This, and the intuition that duration is non-negative, tells you that it must be +1 on the bottom of the _effectDuration fraction.

i don't know how this stuff works.. i'm not a coder, but i hate asking for plugins.. i try my hardest to figure things out on my own..
Everyone starts somewhere! If you're set on doing things yourself (I can relate), then I think that when faced with a problem like this you might benefit by slowing down and looking for more details before you start designing a solution. It's very easy to miss relevant details if you're not careful. Your choice, of course; you know yourself best~

(In this case I think you'd've needed a fair bit of exploring to figure out brightness, but a similar effect may be possible using this.setColorTone([r,g,b,a]) with negative RGB values.)

Happy RPG Making! 👋
Great! In case your enemies revive, you could try adding this patch too (untested):
JavaScript:
;(alias => {
  Sprite_Enemy.prototype.revertToNormal = function() {
    alias.apply(this, arguments);
    if (this._colorFilter)
      this._colorFilter.setBrightness(255);
  };
})(Sprite_Enemy.prototype.revertToNormal);
I.e. "reset brightness whenever a new effect starts".


Note that the core scripts have a plus there, which normally causes the opacity to fade out, i.e. "minus it down to zero".

An expression in the form A *= B means "multiply A by B (and store the result in A)". For a decrease, you would expect to be multiplying by a value smaller than 1. This, and the intuition that duration is non-negative, tells you that it must be +1 on the bottom of the _effectDuration fraction.


Everyone starts somewhere! If you're set on doing things yourself (I can relate), then I think that when faced with a problem like this you might benefit by slowing down and looking for more details before you start designing a solution. It's very easy to miss relevant details if you're not careful. Your choice, of course; you know yourself best~

(In this case I think you'd've needed a fair bit of exploring to figure out brightness, but a similar effect may be possible using this.setColorTone([r,g,b,a]) with negative RGB values.)

Happy RPG Making!
I didn't even know you could use negative values!
That said, i actually needed color tone for something else, because i'm applying a color along side the darken effect.
A lot of fading effects on the super nintendo were oddly done that way.
Also, you'll noticed i await until i can't figure something out on my own to starting asking for help.
Plus i do a LOT of searching on the forums to find solutions before i even ask.

Original thread: https://forums.rpgmakerweb.com/threads/need-help-working-on-a-custom-enemy-collapse-fade-change.176841/