MV Per-character fade-in message animation

Hello! I'm trying to make plugin that makes every character in message to smoothly fade in, but for some reason that doesn't work. I use nwjs 0.49.2 so maybe that is the issue. Is there some error in my code?
JavaScript:
(function() {
    var _Window_Message_startMessage = Window_Message.prototype.startMessage;

    Window_Message.prototype.startMessage = function() {
        _Window_Message_startMessage.call(this);
        this._textFadeDuration = 0;
    };

    var _Window_Base_processNormalCharacter = Window_Base.prototype.processNormalCharacter;

    Window_Base.prototype.processNormalCharacter = function(textState) {
        _Window_Base_processNormalCharacter.call(this, textState);
      
        if (this.isOpen()) {
            this._textFadeDuration = 0;
            this.startTextFadeIn(textState);
        }
    };

    Window_Base.prototype.startTextFadeIn = function(textState) {
        if (!this._textSprite) {
            this.createTextSprite();
        }
      
        var characterSprite = this._textSprite;
        var duration = 20;
      
        if (this._textFadeDuration < duration) {
            characterSprite.alpha = 0;
          
            var fadeInterval = setInterval(function() {
                characterSprite.alpha += 1 / duration;
                this._textFadeDuration++;
              
                if (this._textFadeDuration >= duration) {
                    clearInterval(fadeInterval);
                }
            }.bind(this), 1);
        }
    };

    Window_Base.prototype.createTextSprite = function() {
        this._textSprite = new Sprite();
        this._textSprite.bitmap = new Bitmap(48, 48);
        this.addChild(this._textSprite);
    };

    var _Window_Base_resetFontSettings = Window_Base.prototype.resetFontSettings;

    Window_Base.prototype.resetFontSettings = function() {
        _Window_Base_resetFontSettings.call(this);

        if (this._textSprite) {
            this._textSprite.bitmap.fontFace = this.standardFontFace();
            this._textSprite.bitmap.fontSize = this.standardFontSize();
            this._textSprite.bitmap.textColor = this.normalColor();
        }
    };
})();
You seem to have set the fade time to 20 ms? That's too fast to be able to see the fade-in, especially since 60 fps = 1 render pass every ~17 ms. Also, are you sharing 1 _textFadeDuration variable for all letters?

I'd personally recommend you perform the opacity updates by patching the window's update method instead of setting up a separate loop with setInterval. update gets called every game frame, regardless of framerate. 👋

Also, since you draw to each of those letter sprites, I think you need to call destroy on them to allow their base textures to be garbage collected? Otherwise that'd be a memory leak. (MV's windows might destroy all their child textures as-is...I'm not sure, since I'm more familiar with MZ's code. 😴)

Original thread: https://forums.rpgmakerweb.com/threads/per-character-fade-in-message-animation.161394/