Impact

This forum is read only and just serves as an archive. If you have any questions, please post them on github.com/phoboslab/impact

8 years ago by Arturo

A while ago, I had a problem with impact, which I was able to resolve.
The problem was, that I was using big images for the backgrounds, and the more that I play the game, the more than the cache was full, and at some point, the images wasnt loaded anymore.
http://impactjs.com/forums/help/impact-doesnt-load-the-images-anymore-after-some-levels-using-big-full-images-for-the-background

You can see on the link what I did in the end: Everytime that I load a new level, I remove every image in cache of the level before (in cache will never save this images of background, and will load only when the level is loaded).
I wasnt sure if that was the right solution, but I got it working so far without problem.

Until now. If I play the game and then I return to some of the first levels after a while, the system works... the problem is that for some reasons the levels take a little bit longer than before to load, so there is a moment where you control the character in an empty canvas...

My question: is there a way to know when all the images has been loaded? Like this I could put a loading icon, until I get everything working

Thanks!

8 years ago by Joncom

Not tested, but just an idea:

var loaded = true;
for(var path in ig.Image.cache) {
    if(ig.Image.cache.hasOwnProperty(path) {
        if(!ig.Image.cache[path].loaded) {
            loaded = false;
            break;
        }
    }
}
// "loaded" should be false if any images aren't yet done loading

8 years ago by Arturo

Thank Joncom as always :)

I didnt know the propertly loaded. Thats is gonna be really helpful.
I make a first test, and seems that is gonna works good.

I still wondering why the first time that I play, it doesnt take long to load (even though I delete the cache) but when I go to the menu, and I go back to MyGame, it takes much longer... I think even though my solution of removing background stages on each load (so the one before used) its not really smooth then... But I dont know other way to free the game to get to the limit and not load images at all...
Page 1 of 1
« first « previous next › last »