How do you wait for Bitmaps to finish loading?
I know this isn't the best scenario. Ideally you would tell the ImageManager to load images way in advance, but this is just simply not always possible. Sometimes you need to load images on the fly. The problem is of course that images don't load instantaneously. So the question now is, how do you wait for them to finish loading or rather, how do you know a Bitmap has finished loading?
The obvious things to try would be the functions
and
but they don't work. Both return 'true' despite the Bitmap very clearly not being ready.
For transparency, here is how I determine that the two 'isReady()' functions don't communicate that a Bitmap is ready:
'Image not ready' is never printed to the console and messageImageBitmap.height returns 0 despite 'redRectangle.png' being a 300 x 300 image file.
By the way, I know that is horrible blocking code that I would never use in that way, it was just a quick and dirty way of testing if Bitmap.isReady() or ImageManager.isReady() do what I need them to do.
So with that the question remains, how do I check that a certain Bitmap has finished loading and is now fully ready for usage? Please someone help me, I am going mad over this.
I know this isn't the best scenario. Ideally you would tell the ImageManager to load images way in advance, but this is just simply not always possible. Sometimes you need to load images on the fly. The problem is of course that images don't load instantaneously. So the question now is, how do you wait for them to finish loading or rather, how do you know a Bitmap has finished loading?
The obvious things to try would be the functions
JavaScript:
Bitmap.isReady()
JavaScript:
ImageManager.isReady()
For transparency, here is how I determine that the two 'isReady()' functions don't communicate that a Bitmap is ready:
JavaScript:
let messageImageBitmap = ImageManager.loadPicture('redRectangle');
while((!ImageManager.isReady) || (!messageImageBitmap.isReady)){
console.log('Image not ready')
}
console.log(messageImageBitmap.height);
'Image not ready' is never printed to the console and messageImageBitmap.height returns 0 despite 'redRectangle.png' being a 300 x 300 image file.
By the way, I know that is horrible blocking code that I would never use in that way, it was just a quick and dirty way of testing if Bitmap.isReady() or ImageManager.isReady() do what I need them to do.
So with that the question remains, how do I check that a certain Bitmap has finished loading and is now fully ready for usage? Please someone help me, I am going mad over this.