Problem with delay on drawText on a Bitmap

Hello everyone, how are you? I would like someone to help with something. I tried to understand how the creation of the status window works on the menu and I could not, so I decided to create a mask, leaving the windows invisible and using the index of the members to display pictures and etc. Recently I was trying to insert member information into the image, such as level, current and maximum hp, and current and maximum mp. I used the code below for this:

Code:
Scene_Menu.prototype.janelaStatus = function() {
    var totalMembros = $gameParty.members().length;
    switch(totalMembros) {
    case 1:
        // Personagem 1
        this._personagem1 = new Sprite();
        this._personagem1.x = Graphics.width - 590;
        this._personagem1.y = 32;
        this.addChildAt(this._personagem1, 2);
        break;
    case 2: // A ordem dos membros é de do maior pro menor para sobrepor a ordem das pictures.
        // Personagem 2
        this._personagem2 = new Sprite();
        this._personagem2.x = Graphics.width - 628;
        this._personagem2.y = 135;
        this.addChildAt(this._personagem2, 2);
        // Personagem 1
        this._personagem1 = new Sprite();
        this._personagem1.x = Graphics.width - 590;
        this._personagem1.y = 32;
        this.addChildAt(this._personagem1, 2);
        break;
    case 3: // A ordem dos membros é de do maior pro menor para sobrepor a ordem das pictures.
        // Personagem 3
        this._personagem3 = new Sprite();
        this._personagem3.x = Graphics.width - 673;
        this._personagem3.y = 257;
        this.addChildAt(this._personagem3, 2);
        // Personagem 2
        this._personagem2 = new Sprite();
        this._personagem2.x = Graphics.width - 628;
        this._personagem2.y = 135;
        this.addChildAt(this._personagem2, 2);
        // Personagem 1
        this._personagem1 = new Sprite();
        this._personagem1.x = Graphics.width - 590;
        this._personagem1.y = 32;
        this.addChildAt(this._personagem1, 2);
        break;
    }
};

This will check the total members and create a picture for each one. So, on update, I made them appear:

Code:
Scene_Menu.prototype.update = function() {
    Scene_Base.prototype.update.call(this);
  
    //Exibe a imagem dos personagens e os dados deles pelos membros do grupo.
  
    var totalMembros = $gameParty.members().length;
  
    switch(totalMembros) {
    case 1:
        // Personagem 1
        this._personagem1.bitmap = ImageManager.loadPicture($gameParty.members()[0]._name);
        this._personagem1.bitmap.drawText($gameParty.members()[0]._level, 40, 40, 50, 50, 'center');
        this._personagem1.bitmap.fontSize = 50;
        break;
    case 2: // A ordem dos membros é de do maior pro menor para sobrepor a ordem das pictures.
        // Personagem 2
        this._personagem2.bitmap = ImageManager.loadPicture($gameParty.members()[1]._name);
        this._personagem2.bitmap.drawText($gameParty.members()[1]._level, 40, 40, 50, 50, 'center');
        this._personagem2.bitmap.fontSize = 50;
        // Personagem 1
        this._personagem1.bitmap = ImageManager.loadPicture($gameParty.members()[0]._name);
        this._personagem1.bitmap.drawText($gameParty.members()[0]._level, 40, 40, 50, 50, 'center');
        this._personagem1.bitmap.fontSize = 50;
        break;
    case 3: // A ordem dos membros é de do maior pro menor para sobrepor a ordem das pictures.
        // Personagem 3
        this._personagem3.bitmap = ImageManager.loadPicture($gameParty.members()[2]._name);
        this._personagem3.bitmap.drawText($gameParty.members()[2]._level, 40, 40, 50, 50, 'center');
        this._personagem3.bitmap.fontSize = 50;
        // Personagem 2
        this._personagem2.bitmap = ImageManager.loadPicture($gameParty.members()[1]._name);
        this._personagem2.bitmap.drawText($gameParty.members()[1]._level, 40, 40, 50, 50, 'center');
        this._personagem2.bitmap.fontSize = 50;
        // Personagem 1
        this._personagem1.bitmap = ImageManager.loadPicture($gameParty.members()[0]._name);
        this._personagem1.bitmap.drawText($gameParty.members()[0]._level, 40, 40, 50, 50, 'center');
        this._personagem1.bitmap.fontSize = 50;
        break;
    }
};

The sistem works, the pictures (with the actor face) show on Scene_Menu, but the problem is that the texts only appear written the second time that I return to the main menu.

Can someone help me figure out how to fix this?
The problem is that the bitmap does not get loaded in time. To prevent this, you need to move the code that relies on the bitmap into a load listener.

Here is an example:
Code:
/* ... */
this._personagem1.bitmap = ImageManager.loadPicture($gameParty.members()[0].name());

this._personagem1.addLoadListener(function () {
    this._personagem1.bitmap.drawText($gameParty.members()[0]._level, 40, 40, 50, 50, 'center');
    this._personagem1.bitmap.fontSize = 50;
});

break;
/* ... */
The problem is that the bitmap does not get loaded in time. To prevent this, you need to move the code that relies on the bitmap into a load listener.

Here is an example:
Code:
/* ... */
this._personagem1.bitmap = ImageManager.loadPicture($gameParty.members()[0].name());

this._personagem1.addLoadListener(function () {
    this._personagem1.bitmap.drawText($gameParty.members()[0]._level, 40, 40, 50, 50, 'center');
    this._personagem1.bitmap.fontSize = 50;
});

break;
/* ... */

So, that means when I open my Menu, the game will wait until all the info is loaded and then open the menu?

Another thing, form some reason when my character level up, the old lever still show under the new one. How can I "erase" the draw text and then load again everytime a open my menu? I try to use on Scene_Menu.prototype.start and use the this.janelaStatus.refresh(), but a error pops up.

Original thread: https://forums.rpgmakerweb.com/threads/problem-with-delay-on-drawtext-on-a-bitmap.91220/