Jump to content

Assign onLoad function for every file


Recommended Posts


I have this code in my preload function:

items : [

sprites : [],

preload : function() {
    for(var i in this.items) {
        var name = this.items[i];

        var jsonFile = game.load.json(name, '/json/' + name + '.json');

        jsonFile.onFileComplete.add(function(progress, cacheKey, success, totalLoaded, totalFiles) {
            if(progress == 100) {
                var cache = game.cache.getJSON(cacheKey);

                for(var j in cache) {
                    var spriteName = 'sprite-' + cache[j].name;
                    var sprite = game.load.image(spriteName, '/sprites/' + cache[j].name + '.svg');

        }, this);


How to assing some onFileComplete function (or as callback) for each JSON file and load some sprites based on data that we got from JSON file?

Because, after running this code below I'm getting onFileComplete even for sprite loading part.

Link to comment
Share on other sites

52 minutes ago, rich said:

onFileComplete is a Loader level signal, not a file level signal. The Loader itself dispatches that signal, for any file added to the load queue. There is no way to filter it, you'll have to do that yourself in the callback.

Thanks. Now I'm understand.

But Rich, is this right to have only Loader level signal and not for specific file?

Link to comment
Share on other sites


  • Recently Browsing   0 members

    • No registered users viewing this page.
  • Create New...