Jump to content

Creating a spritesheet with a Render Texture


Kinerius
 Share

Recommended Posts

Hi let me explain what im trying to do here: I need to merge 2 big sprite sheets into one using Render texture with .renderXY() method.
It works OK, but now the problem is i don't have animation frames created for it ( thing that game.loader.spritesheet does )
so im trying to do something like this:

this.game.cache.addRenderTexture(key,renderTexture);sprite.animations.frameData = Phaser.AnimationParser.spriteSheet(this.game,key,width,height);

but then i realized phaser does this in the AnimationParser.spriteSheet method:

        if (typeof key === 'string')        {            img = game.cache.getImage(key);        }        if (img === null)        {            return null;        }

Is there a workaround for this? 
 

Link to comment
Share on other sites

Hi, here is solution, how to create frame data to render texture

            // create render texture            var width = 300;            var height = 300;            this._prerendered = new Phaser.RenderTexture(aGame, width, height);            // add render texture to cache with "MyRenderTexture" key (currently its frameData property is not defined)            this.game.cache.addRenderTexture("MyRenderTexture", this._prerendered);            // create frame data            var frameData = new Phaser.FrameData();            // add single frame "frame0" to it            frameData.addFrame(new Phaser.Frame(0, 50, 50, 100, 100, "frame0"));            // assign created frameData to our render texture            this.game.cache.updateFrameData("MyRenderTexture", frameData, Phaser.Cache.RENDER_TEXTURE);            // just to test ... read "frame0" back from cache            var frame = this.game.cache.getFrameByName("MyRenderTexture", "frame0", Phaser.Cache.RENDER_TEXTURE);
Link to comment
Share on other sites

  • 1 month later...
  • 1 year later...

I could create the render texture and get the frames back, but I couldn't create a sprite sheet from it. Whenever I tried to create a sprite with that texture, I couldn't set the frame on it without effecting all sprites sharing that texture.

Instead, I created a spritesheet from a bitmap data object:

game.cache.addSpriteSheet('key',null,bitmapdata.canvas, framewidth, frameheight);
Link to comment
Share on other sites

 Share

  • Recently Browsing   0 members

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