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

1 decade ago by gxxaxx

I'm working on a project that has a larger number of levels.
The backgrounds for each level are different.
Thus, giving rise to a large download if everything is preloaded before game start.

I was thinking of preloading assets for level 1 through 5 at game start, then load assets for level 6 upon entering level 4, load 7 when going into 5, etc. So that I am always a room or two ahead of the player.

Before re-inventing the wheel, I was wondering if anyone has worked out a mechanism for loading assets after start of game.

Or, is there something about this approach that is totally whack and I should go a different direction?

Thanks for any clues.

1 decade ago by Arantor

I don't think it's totally whack, I think it has potential - not only for the stated reason but there's no reason why you couldn't, for example serve different level files depending on the access level of the user.

The real issue is dealing with the autoloader, but provided that you deal with the loadLevel function much as Biolab does (that is to say, it works out what level must be next and references that in ig.global as an object), I don't see the real problem.

If anything a bigger problem is going to be how to safely cope with the level data not being accessible for any reason.

What I'd imagine is that on the transition screen between levels (to give the player respite and appropriate loading time), you make the relevant AJAX call to fetch the data. This need be nothing more complex than simply inserting a <script> tag dynamically into the page, the browser will do the rest as far as loading and executing the script (even, interestingly, across domains)

The called script probably won't be a plain level, because it'll likely have to have some wrapping to inject it into the current running ig instance but I don't think that would be a problem.

AIUI, levels are simply objects within ig.global, quite literally as ig.global['Level' + levelName], if your file was level1.js, the created object is LevelLevel1 (Level prefix + your file's name with upper-case first character), which will be stored as ig.global['LevelLevel1']. At least, that's my understanding of it, and that object can be referenced and passed to loadLevel as normal.
Page 1 of 1
« first « previous next › last »