Javascript, wait until images are loaded

Joined
Jun 30, 2017
Messages
42
Reaction score
35
First Language
spanish
Primarily Uses
RMMV
Hi, i am working on a plugin for my game that automatically loads parallax images on map enter.

Because in big maps that is slow(1-3 seconds with strange screen effects) i want to show a 'loading image' over screen, then load all parallax images, and when everything is loaded remove the loading image from screen.

I'am using gameScreen.showPicture() to load all that images, but that runs in async, and the function returns before the image is loaded and visible on screen.

My question is: After calling gameScreen.showPicture() many times, how to check/wait until all images are loaded, before proceeding to next step?

Load "loading" image.
Wait for image load.
Load parallax image 1
Load parallax image 2
Load parallax image 3
Load parallax image 4
...
Load parallax image 32
Wait for all images
Hide "loading" image

Any help will be appreciated.
 

Tsukimi-neko

Tsukimi
Veteran
Joined
Oct 25, 2017
Messages
101
Reaction score
278
First Language
Japanese
Primarily Uses
RMMV
Hello!
You can use the ’script’ command and type in:

this.setWaitMode('image');

This will wait until all images in ImageManager ready, to run next command.
By the way, you can load pictures/paralaxes by using:

ImageManager.loadPicture('picture name in img/pictures/');
ImageManager.loadParallax('picture name in img/parallaxes/');

but of couse, showPicture will be fine!
 
Last edited:
Joined
Jun 30, 2017
Messages
42
Reaction score
35
First Language
spanish
Primarily Uses
RMMV
Thanks @cji3bp62000, but i think that only works for commands in a event editor not in plain JS and i'am trying to do all
the work in the plugin side.

Calling this.setWaitMode("Image") automatically returns, also calling ImageManager.loadPicture() automatically returns.

I think maybe i can set this.setWaitMode() and then, re-run my plugin command playing with Game_Interpreter._idx, and doing all the work in 'steps' but i don't know if its a correct approach.
 

LTN Games

Indie Studio
Veteran
Joined
Jun 25, 2015
Messages
704
Reaction score
631
First Language
English
Primarily Uses
RMMV
Last I checked you can easily chain addLoadListener() to loadPicture()., I could be wrong though.
Code:
ImageManager.loadPicture('picture.png').addLoadListener(bitmap => console.log('Bitmap Loaded!, bitmap)
 
Joined
Jun 30, 2017
Messages
42
Reaction score
35
First Language
spanish
Primarily Uses
RMMV
Last I checked you can easily chain addLoadListener() to loadPicture()., I could be wrong though.
Code:
ImageManager.loadPicture('picture.png').addLoadListener(bitmap => console.log('Bitmap Loaded!, bitmap)
That works,
Thanks!
 

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