Writing own HUD, no text is displayed.

Hi guys, I'm currently trying to write my own HUD plugin (I know there are some already, but I kinda want to write as much myself as possible, for learning and license reasons).


The window I created is shown and updated as expected, except it is completely empty... I can't see why, because the string I hand over to the drawText function has the right text and it seems like it gets called correctly (on creation and everytime Scene_Map updates)


Here's what I have:



(function(){
var _map_create_all_windows = Scene_Map.prototype.createAllWindows;
Scene_Map.prototype.createAllWindows = function(){
_map_create_all_windows.call(this);

this.createHUD();
}

Scene_Map.prototype.createHUD = function(){
this._hud = new Window_HUD();
this.addWindow(this._hud);
}

//-----------------------------------------------------------------------------
// Window_HUD
//

function Window_HUD(){
this.initialize.apply(this, arguments);
}

Window_HUD.prototype = Object.create(Window_Base.prototype);
Window_HUD.prototype.constructor = Window_HUD;

Window_HUD.prototype.initialize = function(){
Window_Base.prototype.initialize.call(this);
this.move(0, 0, Graphics.boxWidth, this.fittingHeight($gameParty.members().length));
this.drawContent();
};

Window_HUD.prototype.drawContent = function(){
for(var i = 0; i < $gameParty.members().length; ++i){
var name = $gameParty.members()._name;
var hp = $gameParty.members()._hp;
var maxHp = $gameParty.members().mhp;
var hudText = name + ": " + hp + "/" + maxHp;

this.drawText(hudText, 0, this.lineHeight() * i);
}
}

Window_HUD.prototype.update = function(){
this.move(0, 0, Graphics.boxWidth, this.fittingHeight($gameParty.members().length));
this.drawContent();
}
})();


Anyone has an idea, what I am doing wrong?
Nothing? Too bad. Guess I'll have to look for another way to do this. 


Wish I knew why adding a window to Scene_Map doesn't produce the desired effect though :/
You need to specify a maxWidth when you call drawText

Code:
Window_Base.prototype.drawText = function(text, x, y, maxWidth, align) {
    this.contents.drawText(text, x, y, maxWidth, this.lineHeight(), align);
};
I used "drawText" before and afaik the last to parameters are optional. (I used the function alot in my custom menu and omitting them was totally fine there.)


Tried it anyway with:


this.drawText(hudText, 0, this.lineHeight() * i, Graphics.boxWidth, "left");


instead of


this.drawText(hudText, 0, this.lineHeight() * i);


and it still didn't work. Also I printed out the parameters to the console and yes, Graphics.boxWidth and the other parameters had the expected values.


It's just weird... I traced back the functions too, but I can't find the problem... According to the source code the text should display on screen just fine...
You're not passing anything to the initialize function in Window_Base.


You have:


Window_HUD.prototype.initialize = function(){
Window_Base.prototype.initialize.call(this);
this.move(0, 0, Graphics.boxWidth, this.fittingHeight($gameParty.members().length));
this.drawContent();
};


Try changing to:


Window_HUD.prototype.initialize = function(){
Window_Base.prototype.initialize.call(this,0, 0, Graphics.boxWidth, this.fittingHeight($gameParty.members().length));
this.drawContent();
};




Also, I wouldn't continuously redraw the window in the update function - might cause slower devices to slow down
You're not passing anything to the initialize function in Window_Base.



You're totally right, I just got it to work because of you!


I don't know how I could overlook that...

Also, I wouldn't continuously redraw the window in the update function - might cause slower devices to slow down



Yeah, I know that. I had it that way just for testing purposes. It's already changed in my current version.


Anyway, big thanks to you and sorry for the late answer, but somehow I didn't get an email notification for your post >.<'

Original thread: https://forums.rpgmakerweb.com/threads/writing-own-hud-no-text-is-displayed.57167/