caymanbruce Posted July 30, 2017 Share Posted July 30, 2017 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? Quote Link to comment Share on other sites More sharing options...
xerver Posted July 30, 2017 Share Posted July 30, 2017 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. Quote Link to comment Share on other sites More sharing options...
caymanbruce Posted July 30, 2017 Author Share Posted July 30, 2017 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? Quote Link to comment Share on other sites More sharing options...
xerver Posted July 30, 2017 Share Posted July 30, 2017 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 Quote Link to comment Share on other sites More sharing options...
Recommended Posts
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.