SilverDash

Veteran
Veteran
Joined
Oct 11, 2015
Messages
427
Reaction score
174
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
866
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
427
Reaction score
174
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
427
Reaction score
174
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
427
Reaction score
174
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:

Latest Threads

Latest Posts

Latest Profile Posts

Raptor Revolt Demo 4_10_2021 3_12_09 PM.png

Latest custom tileset work for RAPTOR REVOLT in this beach scene set in the acheroraptor capital in Ridge City, Hell Creek.
unknown.png


I figured it was about time to update the battle sprite for one of my characters. The old one was the first time I ever drew a battle sprite, and filled with lines that shouldn't be there. So far, the new one is cleaner.
EQAQeW8.png

This was supposed to become her neutral talking stance, but now i just feel like she looks a little puzzled :D
I'm also open for any name suggestions, as i seriously suck at those. In my notes everything is just THE CITY or THAT GUY and THIS PRIESTESS or whatever :D
Nearing completion of the first major city of Albert, a vacation getaway city built a long time ago by a king who really didn't want to be invaded.
It’s definitely a great day to fit in some time for me to play no mans sky on PS4

Forum statistics

Threads
110,279
Messages
1,051,931
Members
143,299
Latest member
L_Aede_Aveugle
Top