Loaded sprite starts with 0 x 0 dimensions?

Doktor_Q

I'm not a real doktor, but I am a real Q
Veteran
Joined
Aug 1, 2016
Messages
873
Reaction score
562
First Language
English
Primarily Uses
RMMV
I'm trying to load a sprite sheet using ImageManager.loadCharacter so I can check the image's dimensions, but the first time I try to load the image, the resulting bitmap object has a .height and .width of 0. This happens for all the other resources the game loads, the first time- if it tries to load the same image again (Probably because it's cached), suddenly the width and height are right, and clearly they work when the game needs to use them.


When does it update the dimensions, and does anyone know if there's steps to either a) wait until that's complete, or b) force it to find the actual dimensions?


Thanks in advance!
 

Shaz

Veteran
Veteran
Joined
Mar 2, 2012
Messages
40,098
Reaction score
13,704
First Language
English
Primarily Uses
RMMV
Loading is asynchronous, so you are never going to get the dimensions on the line after you call the load command.  You either have to just allocate a bitmap and let it populate when the image is loaded (check within the update to see if the values are non-zero) or add a callback to happen after the load is complete.  Yanfly's save plugin has an example of how to do that.  Or change it to load synchronously, which is an option if your game is never going to be run from a browser and download its resources at runtime.
 
Last edited by a moderator:

Doktor_Q

I'm not a real doktor, but I am a real Q
Veteran
Joined
Aug 1, 2016
Messages
873
Reaction score
562
First Language
English
Primarily Uses
RMMV
I always forget these are meant to be usable in a browser. That'd explain why it uses so asynchronous calls.
 

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

Latest Threads

Latest Profile Posts

Couple hours of work. Might use in my game as a secret find or something. Not sure. Fancy though no? :D
Holy stink, where have I been? Well, I started my temporary job this week. So less time to spend on game design... :(
Cartoonier cloud cover that better fits the art style, as well as (slightly) improved blending/fading... fading clouds when there are larger patterns is still somewhat abrupt for some reason.
Do you Find Tilesetting or Looking for Tilesets/Plugins more fun? Personally I like making my tileset for my Game (Cretaceous Park TM) xD
How many parameters is 'too many'??

Forum statistics

Threads
105,867
Messages
1,017,061
Members
137,575
Latest member
akekaphol101
Top