Jump to content

Difference between rendering a Container and rendering a RenderTexture


caymanbruce
 Share

Recommended Posts

I am confused with the two main methods to animate objects in pixi.js.

The first one is to build a sprite and put it in a PIXI.Container. I can then add this container as a child of the PIXI stage. Every tick of the animation I just need to update the sprite's position and PIXI will handle the rest for me.

I can also build a sprite or a displayObject and create a RenderTexture which is about the same size of what I want to render. Then I use 

renderer.render(DisplayObject, RenderTexture); 

to render it on the screen. This works fine too. I still need to update the position on every tick so the displayObject will animate.

But what is the difference between using a Container and a RenderTexture? There must be a reason we have two options to render something. What use cases are these two methods best fitted in?

Link to comment
Share on other sites

RenderTexture renders everything in a container's children tree to a single texture. If you have a lot of sprites, which are all static, you may not want to have to iterate a tree with all those sprites, update all their transform matrices and render them all. Instead you can render the entire tree to a texture then render that once with a single sprite.

If you just have one sprite running around, then rendering to a renderTexture first, then using that in another sprite and rendering that is going to be slower.

Link to comment
Share on other sites

3 hours ago, xerver said:

RenderTexture renders everything in a container's children tree to a single texture. If you have a lot of sprites, which are all static, you may not want to have to iterate a tree with all those sprites, update all their transform matrices and render them all. Instead you can render the entire tree to a texture then render that once with a single sprite.

If you just have one sprite running around, then rendering to a renderTexture first, then using that in another sprite and rendering that is going to be slower.

Thanks that sums it up. 

How about mixed situation? Such as a MiniMap.  I have read some discussion about writing MiniMap in Phaser using RenderTexture. I used to do that with simple sprite and container. A MiniMap has a lot of static objects, in the mean time it also shows local player movements in a constrained space. Let's make it simple so that I only use a dot to represent the local player. So there will be one moving sprite, but maybe hundreds of static sprites on the map. In this case, performance-wise, is it better to use a container or a RenderTexture?

Link to comment
Share on other sites

8 hours ago, caymanbruce said:

Thanks that sums it up. 

How about mixed situation? Such as a MiniMap.  I have read some discussion about writing MiniMap in Phaser using RenderTexture. I used to do that with simple sprite and container. A MiniMap has a lot of static objects, in the mean time it also shows local player movements in a constrained space. Let's make it simple so that I only use a dot to represent the local player. So there will be one moving sprite, but maybe hundreds of static sprites on the map. In this case, performance-wise, is it better to use a container or a RenderTexture?

It is (always) better to measure and see :)

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...
 Share

  • Recently Browsing   0 members

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