scofield Posted April 22, 2016 Share Posted April 22, 2016 Hello. I have this code in my preload function: items : [ 'file1', 'file2', ], 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.sprites.push(spriteName); } } }, 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 More sharing options...
rich Posted April 22, 2016 Share Posted April 22, 2016 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. Link to comment Share on other sites More sharing options...
scofield Posted April 22, 2016 Author Share Posted April 22, 2016 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 More sharing options...
rich Posted April 22, 2016 Share Posted April 22, 2016 Yes because calling load.image (etc) doesn't return a File object (there is no such thing in Phaser), it returns the Loader instance. As there's no concept of a 'file object', there's nothing to actually bind a signal to. Link to comment Share on other sites More sharing options...
Recommended Posts