Hello there,
I've been recently trying a lot to have a window displayed and display several images inside that window, but no matter how much I beat my head I can't figure out why the pictures will not properly load since first attempts...
And even worse, I have to attempt to call the images several times in order to display them, sometimes on mobile it does not even load at all when calling the window for the first time, despite having that timedout.
Could someone please tell me what am I doing wrong?
I've been recently trying a lot to have a window displayed and display several images inside that window, but no matter how much I beat my head I can't figure out why the pictures will not properly load since first attempts...
And even worse, I have to attempt to call the images several times in order to display them, sometimes on mobile it does not even load at all when calling the window for the first time, despite having that timedout.
JavaScript:
////////////////////////////
// This is just 90% of the script to present it logic regarding updating and displaying images
////////////////////////////
function Scene_ImgCreation() {
this.initialize.apply(this, arguments);
}
Scene_ImgCreation.prototype = Object.create(Scene_MenuBase.prototype);
Scene_ImgCreation.prototype.constructor = Scene_ImgCreation;
Scene_ImgCreation.prototype.initialize = function() {
Scene_MenuBase.prototype.initialize.call(this);
};
Scene_ImgCreation.prototype.create = function() {
Scene_MenuBase.prototype.create.call(this);
var ww = Graphics.boxWidth;
this._myWindow = new Window_ImageContainer(ww - 360, Graphics.boxHeight - 162, 360, 162);
var wy = this._myWindow.height;
var wh = Graphics.boxHeight - wy;
ImageManager.reservePicture("test/placeholderImg"); // Attempt to preload it
this.addWindow(this._myWindow);
};
// Start creating the window itself
Window_ImageContainer.prototype = Object.create(Window_Base.prototype);
Window_ImageContainer.prototype.constructor = Window_ImageContainer;
Window_ImageContainer.prototype.initialize = function(x, y, width, height) {
Window_Base.prototype.initialize.call(this, x, y, width, height);
this.needRefresh = true;
// This first time will never dispaly the image, but properly starts loading it to make the ImageManager busy
this.drawPicture("test/placeholderImg", 10, 10);
setTimeout(this.timedOut.bind(this), 300); // I need a timedout to refresh again after X frames so we don't refresh it every frame
this.refresh();
};
Window_ImageContainer.prototype.timedOut = function() {
this.refresh();
}
Window_ImageContainer.prototype.refresh = function() {
this.contents.clear();
if (ImageManager.isReady() == true) {
this.drawPicture("test/placeholderImg", 10, 10); // Barely now the image gets displayed
this.needRefresh = false;
}
}
Window_ImageContainer.prototype.drawPicture = function(filename, x, y) {
var bitmap = ImageManager.loadPicture(filename);
this.contents.blt(bitmap, 0, 0, bitmap._canvas.width, bitmap._canvas.height, x, y);
};
Window_ImageContainer.prototype.update = function() {
Window_Base.prototype.update.call(this);
if (!ImageManager.isReady()) {
this.needRefresh = false;
this.refresh();
}
if (ImageManager.isReady() && this.needRefresh == true) {
this.refresh();
}
};
Could someone please tell me what am I doing wrong?