Jump to content

Phaser: onPackComplete callback can't acces assets just loaded


JohnyBravo
 Share

Recommended Posts

Hi Guys,

 

I just try to optimize game with huge pack of assets, and the idea is to load pack of assets, ant then do something in the game. I experienced strange behaviour of onPackComplete callback, wich is illustrated by following code example:

 

assets.json:

{    "preloader": [{        "type": "image",        "key": "pickard",        "url": "assets/pickard.gif",        "overwrite": false    }]}

 

var main = {    preload: function() {    },    create: function() {        game.load.reset();        //following section is not working - but I can see in debug console/network console that file is loaded        game.load.pack('preloader', 'assets.json');        game.load.onPackComplete.add(function(hasBeenLoaded) {            console.log(hasBeenLoaded);            game.add.sprite(0, 0, 'pickard'); //Gives: "Texture with key 'pickard' not found."        }, this);        //this is working just fine        game.load.image('pickard', 'assets/pickard.gif');        game.load.onLoadComplete.add(function() {            game.add.sprite(0, 0, 'pickard');        })        game.load.start();    },    update: function() {        },};var game = new Phaser.Game(592, 296, Phaser.AUTO, 'gameDiv');game.state.add('main', main);game.state.start('main');

I tried to move preloading of pack to preload function, and later add sprite in create function, works OK.

 

Well, as far as I could expect, assets should be ready to use when onPackComplete callback is being called, am I right?

Link to comment
Share on other sites

The onPackComplete event is dispatched when the pack file itself has been loaded and parsed, and all of the files you defined in the pack have been added to the file queue ready to be loaded. If you want to know when the load has finished use onFileComplete or onLoadComplete.

 

I'll update the docs to make this more clear.

Link to comment
Share on other sites

 Share

  • Recently Browsing   0 members

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