Problem with delay on drawText on a Bitmap

Virage_Detoldev

Villager
Member
Joined
Jan 6, 2018
Messages
18
Reaction score
7
First Language
Portuguese
Primarily Uses
RMMV
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?
 

waynee95

Inactive
Veteran
Joined
Jul 2, 2016
Messages
682
Reaction score
598
First Language
German
Primarily Uses
RMMV
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;
/* ... */
 

Virage_Detoldev

Villager
Member
Joined
Jan 6, 2018
Messages
18
Reaction score
7
First Language
Portuguese
Primarily Uses
RMMV
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.
 

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

Latest Threads

Latest Profile Posts

Couple hours of work. Might use in my game as a secret find or something. Not sure. Fancy though no? :D
Holy stink, where have I been? Well, I started my temporary job this week. So less time to spend on game design... :(
Cartoonier cloud cover that better fits the art style, as well as (slightly) improved blending/fading... fading clouds when there are larger patterns is still somewhat abrupt for some reason.
Do you Find Tilesetting or Looking for Tilesets/Plugins more fun? Personally I like making my tileset for my Game (Cretaceous Park TM) xD
How many parameters is 'too many'??

Forum statistics

Threads
105,867
Messages
1,017,062
Members
137,575
Latest member
akekaphol101
Top