Jump to content
This forum will be closing down. Please move to the respective dedicated project forums.

Prerender a group of sprites to a single sprite


borisyankov
 Share

Recommended Posts

Edit: I clearly need to check the post thread - this answer is relevant to pixi, not Phaser (though phaser can/does render via pixi, so this may be a valid solution still?)

You can look at using a RenderTexture to blit to a canvas, or (a solution I deployed recently), simply manage another Pixi display list (another Stage object) with it's own renderer (with a view that you never add to the DOM). So long as any secondary Stage objects don't use interactivity (i.e. no unnecessary overhead), it'll let you do some pretty powerful things with 'pre-composition', etc.

You can use the secondary renderer's view as a new baseTexture via Sprite.fromCanvas()

Edited by inductible
Link to comment
Share on other sites

There are 2 different ways to approach this. First would be a RenderTexture. I actually just put a few examples into the dev branch showing how to use them, so you could start there, but essentially you can paint any Sprite (or Group) to a RenderTexture. In Canvas it creates an "offscreen" canvas, in WebGL it writes direct to the frame buffer, so it's really fast. It's limited in that  you can only draw image data to it though.

 

I've also added a new object (again only in dev right now) called a BitmapData. This is a pure hidden canvas, so anything you can do on a canvas object you can do on this. I.e. gradient fills, lines, copying chunks of it around, etc. It can then be used as the base texture for any Sprite. This is more expensive in WebGL mode as it has to re-upload the texture to the GPU each time you update it, but it's more flexible depending on the effect you're trying to achieve.

 

For this thread specifically though I'd recommend a RenderTexture.

Link to comment
Share on other sites

 Share

  • Recently Browsing   0 members

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