Help: width or height properties of a bitmap/image?

wrigty12

Just a QAer playing with Javascript
Veteran
Joined
Jan 11, 2014
Messages
624
Reaction score
159
First Language
English
Primarily Uses
RMMZ
I am trying to retrieve the value of the width/height of a picture that I import with ImageManager.loadBitmap. When I try the following code in the game console, it works just fine:


ImageManager.loadBitmap("img/pictures/puzzle/", "Castle").width;


However, once I try to set the exact same code to a variable within my plugin, I always get 0. This happens even if I set the image without the ".width" portion to a variable, then do variable.width.


What am I doing wrong? I cannot find any other way to retrieve the width of an image I wish to import.


Thanks!
 

Shaz

Veteran
Veteran
Joined
Mar 2, 2012
Messages
40,098
Reaction score
13,704
First Language
English
Primarily Uses
RMMV
Because images are loaded asynchronously, you need to wait a while, until the image is fully loaded, before you can look at the properties.  When you try in the game console, is that AFTER you have tried to do it in the script?  The script has started the load, and by the time you get that typed into the console, the load has completed.


I don't think a loop would be suitable for this, as it might stop other processing from happening.  It should be in an update function or something like that, that runs within the engine's existing looping cycle.  You can check ImageManager.isReady to determine whether the image is still being loaded.  Once that returns true, you'll be able to access the properties.
 

wrigty12

Just a QAer playing with Javascript
Veteran
Joined
Jan 11, 2014
Messages
624
Reaction score
159
First Language
English
Primarily Uses
RMMZ
Ah, alright I will keep that in mind and rework my methods. Thanks!
 

Victor Sant

Veteran
Veteran
Joined
Mar 17, 2012
Messages
1,694
Reaction score
1,452
First Language
Portuguese
Primarily Uses
bitmap = ImageManager.loadBitmap("img/pictures/puzzle/", "Castle")
bitmap.addLoadListener(youFunction.bind(this, bitmap))

yourFunction = function(bitmap) {
 // do whatever you need to do after the bitmap is loaded
}




if what you need to do is on a update you can use


if (bitmap.isReady()) {
  // do whatver you need with the bitmap
}


Obviously, those are just pseudo codes to give you an idea of what can be done, but everything will depend on the context of the what you're trying to do.
 

wrigty12

Just a QAer playing with Javascript
Veteran
Joined
Jan 11, 2014
Messages
624
Reaction score
159
First Language
English
Primarily Uses
RMMZ
Thanks Victor! I didn't even know an addLoadListenter function existed.


I think I'm going to load up the bitmaps with the plugin's parameters so I can also edit any image filenames, but Ill definitely keep your setup in mind in case that doesn't end up working for my plugin.
 

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

Latest Threads

Latest Profile Posts

How many parameters is 'too many'??
Yay, now back in action Happy Christmas time, coming back!






Back in action to develop the indie game that has been long overdue... Final Fallacy. A game that keeps on giving! The development never ends as the developer thinks to be the smart cookie by coming back and beginning by saying... "Oh bother, this indie game has been long overdue..." How could one resist such? No-one c
So I was playing with filters and this looked interesting...

Versus the normal look...

Kind of gives a very different feel. :LZSexcite:
To whom ever person or persons who re-did the DS/DS+ asset packs for MV (as in, they are all 48x48, and not just x2 the pixel scale) .... THANK-YOU!!!!!!!!! XwwwwX

Forum statistics

Threads
105,853
Messages
1,016,990
Members
137,562
Latest member
tamedeathman
Top