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 Heiko

Hi

How do I delay load a game class?

Is this possible, and what do I have to consider when doing this?

I would like to be able to click a button in html, and this should then load game1.js, clear the old game (delete/unload it), and then set the new game class after javascript code has been downloaded.

If I click another html button it should load another_game.js, clear the old one and set the new game class.

1 decade ago by Heiko

I was looking at different ways to delay load javascript but couldn't decide which would work best until I dug a bit deeper into the impact engine and found _loadScript().
I managed to delay load the initial game.

(Maybe this will help other people trying to do something similar.)

Next up need to delay load a second game, get notified when gamecode loaded, and then switch to next game using setGame().

Then need to figure out how I can cleanup resources from previous game loaded. Not sure if this is possible yet. Resources are loaded global to impact, not the game.

If this doesn't work, the only alternative I see would be to reload impact whenever a new game is loaded from the DOM game menu.

1 decade ago by Joncom

The way Impact tends to work is that it loads all needed resources at the beginning. I get the impression you're wanting to load up only part of the game, and then when the user clicks a button, load the rest?

You may be needing to do some AJAX. Unfortunately I'm not well versed with that... good luck.

1 decade ago by Heiko

Yes that is exactly what we want to do.

And I was looking at AJAX options (also not to well versed with AJAX) - but that's where I found the _loadScript() command in 'impact' module. Which loads script and gets a callback when script loaded.

If you end up having 30 games and they all have their own graphics and game code, then you don't want to load it all at once.

Only options I see are:
* either reloading the whole ig namespace each time user switches from one game to another, or else
* keeping the impact framework loaded and only reload the game code.

Note that users could switch between games quite frequently - so its not like the user only selects one game and then goes on playing it.

As an additional improvement would then add a caching mechanism that keeps the last 2-3 games loaded, for faster switching - if user switches back to previous game.
Page 1 of 1
« first « previous next › last »