oberhamsi/gamejs — Issue #41: loading of assets after ready()
Author: oberhamsi
Created: 2012-01-16 09:17:04+00:00
State: open

currently only one set of assets can be preloaded before ready() is executed. for large games it would be useful to be able to load additional resources after the game is already initialized (e.g. for loading the next map assets).

API RFC:

calling `preload()` after initialization triggers another async preloader. Once all assets were loaded, an event `PRELOAD_SUCCESS` or `PRELOAD_ERROR` is triggered.

the `preloadId` returned by `preload()` and present in the resulting event is there, in case the game triggers multiple `preload()`s and needs to differantiate which one was finished:

// in game code:
var preloadId = gamejs.preload(['./images/foo.png']);

// in event handler:
if (event.type === gamejs.event.PRELOAD_SUCCESS) {
gamejs.log('Loaded assets ', event.preloadId);
}