[Solved] FaceGraphics invisible, how to draw it?

SilverDash

Veteran
Veteran
Joined
Oct 11, 2015
Messages
424
Reaction score
171
First Language
Dutch
Primarily Uses
RMMV
I have this code in a window:

this.drawActorFace(actor, 0, 0, 144, 144); // no image is drawn. This method is from Window_Base.Of course no image is drawn because, Javascript loads them asynchronously in the RM code further down the road (in the ImageManager).

So basically, I need to somehow call the this.refresh() again after the image is loaded, or better, not call refresh until it's loaded. How do I hook into that? Is there a method that is called when the bitmap finishes loading or something? Because I rather not loop the refresh or something else checking every frame if a face-bitmap finished loading.

I took a look at how Window_MenuStatus did it but couldn't find it. Because they must have had that same problem and solved it somehow. But how?
 
Last edited by a moderator:

Iavra

Veteran
Veteran
Joined
Apr 9, 2015
Messages
1,797
Reaction score
863
First Language
German
Primarily Uses
Is there a method that is called when the bitmap finishes loading or something?
Yep:
Code:
bitmap.addLoadListener(callback);
 

SilverDash

Veteran
Veteran
Joined
Oct 11, 2015
Messages
424
Reaction score
171
First Language
Dutch
Primarily Uses
RMMV
I can't get it to work

var alias_silv_skillGem_Scene_Window_Base_drawFace = Window_Base.prototype.drawFace;Window_Base.prototype.drawFace = function(faceName, faceIndex, x, y, width, height){    alias_silv_skillGem_Scene_Window_Base_drawFace.call(this, faceName, faceIndex, x, y, width, height);    bitmap.addLoadListener(this.refresh); // <<<<<<<<<< crash, bitmap is only known in the original drawFace...};Shameless overwrite attempt, but also crashes:

Window_SG_CharacterInfo.prototype.drawFace = function(faceName, faceIndex, x, y, width, height) { width = width || Window_Base._faceWidth; height = height || Window_Base._faceHeight; var bitmap = ImageManager.loadFace(faceName); bitmap.addLoadListener(this.refresh); // <<<<<<<<<< added line. var pw = Window_Base._faceWidth; var ph = Window_Base._faceHeight; var sw = Math.min(width, pw); var sh = Math.min(height, ph); var dx = Math.floor(x + Math.max(width - pw, 0) / 2); var dy = Math.floor(y + Math.max(height - ph, 0) / 2); var sx = faceIndex % 4 * pw + (pw - sw) / 2; var sy = Math.floor(faceIndex / 4) * ph + (ph - sh) / 2; this.contents.blt(bitmap, sx, sy, sw, sh, dx, dy);};
Code below also crashes but this time on the refresh(). Because this.refresh is not yet known to Javascript if the bitmap finishes loading before Javascript finished creating the object I suppose...

Code:
Window_SG_CharacterInfo.prototype.initialize = function(){    ....    this.refresh();    var bitmap = ImageManager.loadFace(Silv.SG_Scene.ActiveActor.faceName());    bitmap.addLoadListener(this.refresh()); //     bitmap.addLoadListener(this.refresh); yields same result as does: bitmap.addLoadListener(refresh);};Window_SG_CharacterInfo.prototype.refresh = function(){    this.contents.clear(); // <<< crash. this.contents is undefined.... Because the this.refresh() will crash if the object hasn't been fully created by JS before the image finishes loading...    this.render();};
 
Last edited by a moderator:

Jeremy Cannady

Coldfire
Veteran
Joined
Oct 25, 2015
Messages
449
Reaction score
268
First Language
English
partyWindow.prototype.preloadImages = function(){ for(var i = 0; i < $gameParty.members().length; i++){ var bitmap = ImageManager.loadCharacter($gameParty.members()._characterName); bitmap.addLoadListener(function() {this.refresh()}.bind(this)); }; };partyWindow.prototype.drawActorList = function(index) { var rect = this.itemRect(index); var actor = $gameParty.members()[index]; this.drawCharacter(actor._characterName, actor._characterIndex, rect.x + 48 / 2, rect.y + 48); };This is the code I use to preload my actor images then draw them in a window. Works for me. Code is based off of windows selectable but that doesn't matter.
 

SilverDash

Veteran
Veteran
Joined
Oct 11, 2015
Messages
424
Reaction score
171
First Language
Dutch
Primarily Uses
RMMV
Thanks to both your answers I found the solution (place in initialize):

var preload_bmp = ImageManager.loadFace(Silv.SG_Scene.ActiveActor.faceName()); preload_bmp.addLoadListener(function() {this.refresh()}.bind(this));It seems I messed up the code for adding the addLoadListener. I had to add .bind(this). Also once pre-loaded they stay cached which is good. So buildin-RM-code can also use it.
 
Last edited by a moderator:

SilverDash

Veteran
Veteran
Joined
Oct 11, 2015
Messages
424
Reaction score
171
First Language
Dutch
Primarily Uses
RMMV
Sadly that did not quite do the trick. Loading the scene for a 2nd time will crash:

Object.defineProperty(Window.prototype, 'contents', { get: function() { return this._windowContentsSprite.bitmap; // <<<<<<<< crash: TypeError: Cannot read property 'bitmap' of undefined }, set: function(value) { this._windowContentsSprite.bitmap = value; }, configurable: true});called from here:

Window_Selectable.refresh = function(){ if (this.contents) // <<<<<<<<<< here the function is called that causes the crash { this.contents.clear(); this.drawAllItems(); }};
So the default RM-code checks for this.contents, which requires this._windowContentsSprite to be initialized... Maybe the default RM code should have checked that as well?

I solved it by pre-loading the bitmap AFTER the Window_Base has been fully initialized instead of before. Because of the pre-loaded image was already in image-cache, it would attempt to refresh() the Window immediately (before the window even has contents).
 
Last edited by a moderator:

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

Latest Threads

Latest Profile Posts

so hopefully tomorrow i get to go home from the hospital i've been here for 5 days already and it's driving me mad. I miss my family like crazy but at least I get to use my own toiletries and my own clothes. My mom is coming to visit soon i can't wait to see her cause i miss her the most. :kaojoy:
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

Forum statistics

Threads
105,868
Messages
1,017,070
Members
137,577
Latest member
SadaSoda
Top