jmp909 Posted September 28, 2015 Share Posted September 28, 2015 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 cachevar sprite2 = this.game.add.sprite(0,0,renderTexture); Link to comment Share on other sites More sharing options...
jmp909 Posted September 28, 2015 Author Share Posted September 28, 2015 this seemed to work.. is it the correct approach? var sprite = this.game.add.sprite(0,0,this.game.cache.getRenderTexture('starRT').texture);j pyre 1 Link to comment Share on other sites More sharing options...
pyre Posted March 16, 2017 Share Posted March 16, 2017 This worked well for me, thanks! I'm also wondering if this is the correct approach? Link to comment Share on other sites More sharing options...
Recommended Posts