MZ Trouble with Resizing Bitmap

Hi all,

I am attempting to create some custom plugins and having trouble trying to resize the bitmap of a background before it is displayed on screen.

I've mostly been creating and modifying code from the engine code as a starting point and got some things working nicely. However, creating a background sprite doesn't seem to resize the first time the main menu is created.

menu background resize.jpg


The bottom part of this image shows the background sprite correctly stretched, but only the second time the main menu is open, and stays that way next. A minor issue, but would like to resolve it.

The code I have to update the background sprite is as follows:

JavaScript:
function SL_MM_Scene() {
    this.initialize(...arguments);
}
SL_MM_Scene.prototype = Object.create(Scene_MenuBase.prototype);
SL_MM_Scene.prototype.constructor = SL_MM_Scene;
SL_MM_Scene.prototype.initialize = function() {
    Scene_MenuBase.prototype.initialize.call(this);
}
SL_MM_Scene.prototype.create = function() {
    Scene_MenuBase.prototype.create.call(this);
    this.createMainMenu();
    this.createActorsView();
}

...

SL_MM_Scene.prototype.createBackground = function() {
    const bitmap = ImageManager.loadPicture("Menu_Background");
    bitmap.resize(Graphics.boxWidth, Graphics.boxHeight);
    this._backgroundSprite = new Sprite();
    this._backgroundSprite.bitmap = bitmap;
    this.addChild(this._backgroundSprite);
}

Any ideas why this code wouldn't update the bitmap the first time around or is there a better way to do this?
File data is fetched asynchronously: if the image is not already in memory, your resize statement will act on a blank canvas rather than the intended image data. RMMZ's Bitmap wrapper offers a load listener structure so you can attach functions to run after the image has loaded.

Try replacing this line:
JavaScript:
    bitmap.resize(Graphics.boxWidth, Graphics.boxHeight);
...with something like this:
JavaScript:
    bitmap.addLoadListener(
        bmp => bmp.resize(Graphics.boxWidth, Graphics.boxHeight)
    );

Original thread: https://forums.rpgmakerweb.com/threads/trouble-with-resizing-bitmap.151049/