Hello fellow developers,
I'm completely new to Javascript, though I have work experience in C languages.
As a beginner exercise, I want to do a simple thing: resize an image that I load to fit with the current resolution.
So I have a high resolution image (1920*1080) that I put as a battleback1 for testing (it is from Blazblue btw). When I simply load it with MV, the image is cropped, as it's too big to fit the default resolution.
Now, I'm not trying to have a bigger resolution at this point, but only to adapt my image to the screen. So I did this (sorry for the C syntax ^^'):
var alias_Spriteset_Battle_battleback1Bitmap = Spriteset_Battle.prototype.battleback1Bitmap;
Spriteset_Battle.prototype.battleback1Bitmap = function()
{
var battleback1 = alias_Spriteset_Battle_battleback1Bitmap.call(this);
battleback1.resize(Graphics.width,Graphics.height);
console.log(battleback1.width);
return battleback1;
}
As you can imagine, this does
not work, and I came to understand it was because Javascript does not wait for the image to be loaded before doing stuff with it. When testing I realized something interesting (if you want to look at the attached images, please ignore the position of the other sprites, that's my next assignment!). On the first fight, the BG image is cropped, as if there was no resize. But starting the second battle (without restarting the game), the image has been resized. I assume that's because the image was already loaded somewhere, so it could resize it.
Apparently, I'm doing it wrong. I apologize if this seems really silly...
By the way, I've also tried this:
var alias_Spriteset_Battle_battleback1Bitmap = Spriteset_Battle.prototype.battleback1Bitmap;
Spriteset_Battle.prototype.battleback1Bitmap = function()
{
var battleback1 = alias_Spriteset_Battle_battleback1Bitmap.call(this);
battleback1._onLoad()
{
battleback1.resize(Graphics.width,Graphics.height);
}
return battleback1;
}
I was delighted to see that it worked for the first battle... but after that, the BG is just black for the second and on...
