Jump to content

Cache sprite created from Phaser.Graphics


weil
 Share

Recommended Posts

Hi there.

I was able to create an image from Phaser.Graphics instance in such way:

var graphics = new Phaser.Graphics(this.game, 0, 0);

graphics.beginFill(0x90EE90);
graphics.drawRect(0, 0, len, len);
graphics.endFill();

var img = new Phaser.Image(this.game);
img.loadTexture(graphics.generateTexture());

Now I'd like to cache this image so I could easily create sprites using its key. Unfortunately I'm unable to find a way to do so. Is that possible?

Link to comment
Share on other sites

You're right, I was thinking of the BitmapData method.

You can do 

game.cache.addItem('name', Phaser.Cache.TEXTURE);
// …
game.cache.getItem('name', Phaser.Cache.TEXTURE);

But I don't think you'd be able to use the string key alone, because that searches the image cache only.

Link to comment
Share on other sites

 Share

  • Recently Browsing   0 members

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