tagpro-game / tagpro-issues

Public repository to report and review TagPro bugs, enhancements and suggestions.
15 stars 4 forks source link

Delay tagpro.ready.after callbacks when tagpro.resourcesLoaded == true #278

Open keratagpro opened 8 years ago

keratagpro commented 8 years ago

I don't really know the internals of the game that well, so I'm not sure how much this would break things, but I thought this would make sense:

tagpro.ready.after = function(callback) {
    if (tagpro.resourcesLoaded) {
-       callback();
+       setTimeout(callback, 0);
    }
    else {
        tagpro._afterReadyCallbacks.push(callback);
    }
}

A use case I noticed was to have stuff run after tagpro.ready(createRenderer), but before tagpro.ready.after(tr.start). With the above change, this would work correctly in a userscript:

tagpro.ready(function() {
    tagpro.renderer.options.transparent = true;
});

which looks a lot simpler than the existing workaround: https://www.reddit.com/r/TagPro/comments/2xwwz4/userscript_newcomptes_transparent_canvas/