Jump to content

Dynamically created atlas fails to load due to async creation


markp
 Share

Recommended Posts

Ref v2.0.1.

I'm creating an atlas from a bitmap canvas that is drawn to within the preload event of my stage.  The image data is dynamic in nature so cannot be a static image asset.

var bmd = this.game.add.bitmapData(x,y);// draw on bmd.ctx;// build atlasData structure to define frames of sprite data drawn to bmd.ctxthis.game.load.atlas('mykey', bmd.canvas.toDataURL(), null, atlasData);

The issue I have is that the drawing process I have available to me can only inform me of its completion by way of a completion event on the dom.  As I can only call the bmd.canvas.toDataURL() method when drawing is complete I also cannot load the atlas until drawing is complete which means the call to this.game.load.atlas(...) occurs during the completion event process.

 

The completion event is likely to occur in time after the end of the preload and so the loader starts before I get the chance to add 'mykey' meaning my asset is not tracked for loading.  This results in empty images displayed where sprites should be.

 

Is there a way of adding an async created asset into the loader or do I need to extend the loader to support this feature?

 

 

 

 

 

Link to comment
Share on other sites

Could you not use states to set up a 'boot' state (as in the bundled examples) which only progresses when your dynamic asset has been created? This way you are controlling the progression of the states rather than allowing Phaser to determine when everything has been done.

Link to comment
Share on other sites

 Share

  • Recently Browsing   0 members

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