Jump to content

caching graphics to RenderTexture or BitmapData and adding to cache


jmp909
 Share

Recommended Posts

Hi,

 

I'm trying to work out how to create a shape with graphics, cache it and add it to a sprite to use repeatedly

 

I was trying to recreate the intro background on this video (see below, not the video thumbnail but the first thing you see when you actually play it). I realised drawing all the star graphics and fills directly over time would probably be too slow, so it would be better to cache the star & it's trail as a bitmap and then create multiple sprites from that.

 

I want to create the graphic early on and pull it out of the cache later. I'm getting an error though. The key is there but it can't find the texture. Does it need longer to store before trying to pull it out again?

 

Obviously I could use a PNG but i'd prefer to be able to generate the graphics at runtime

 

thanks for any advice. 

J

// draw graphics to renderTexturevar renderTexture = this.add.renderTexture(graphics.width, graphics.height);renderTexture.renderXY(graphics, 0, 0, true);// add renderTexture to cachethis.game.cache.addRenderTexture('starRT', renderTexture );// check starRT is in cacheconsole.log(this.game.cache.checkRenderTextureKey('starRT')) // true// Error: Phaser.Cache.getImage: Key "[object Object]" not found in Cache.var sprite = this.game.add.sprite(0,0,this.game.cache.getRenderTexture('starRT'));sprite.x=128;

this works fine though, but obviously it's not being pulled from the cache

var sprite2 = this.game.add.sprite(0,0,renderTexture);

post-16536-0-13435700-1443408545.jpg

Link to comment
Share on other sites

  • 1 year later...
 Share

  • Recently Browsing   0 members

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