bp74 / StageXL

A fast and universal 2D rendering engine for HTML5 and Dart.
http://www.stagexl.org
Other
880 stars 82 forks source link

Is it possible to re render only animation objects #319

Open JungleeRaju opened 5 years ago

JungleeRaju commented 5 years ago

I have a query regarding stage rendering feature.

Let us say there are plenty of objects on my game and few objects that are having animation(for example graphics gets updated for these objects). Can i re render only the animation objects as per animation and stop rendering other objects. Is it really possible to do this?

If possible, Is it a good idea to do this?

JungleeRaju commented 5 years ago

Basically my interest is on stopping rendering of static objects so that i can save some cpu usage of the application.

Otherwise if animation objects are animating continuously, i have to set renderMode to ONCE continously and it is same as setting renderMode to AUTO.

Please suggest...

bp74 commented 5 years ago

Hi, thanks for the question. If a DisplayObjectContainer has many children, it may help to call the "applyCache" method on the DisplayObjectContainer. This way all children are rendered to a texture and the following render passes will use this texture to render the DisplayObjectContainer.

But there are a few things you need to consider. If you use the WebGL renderer, many textures will cause many render calls to the GPU, which is bad and slow. If you only use the applyCache method on a few DisplayObjectContainers its not an issue, but if you do it on e.g. 50 or even more it is a problem.

The most important thing to get best performance is texture management (assuming you use the WebGL renderer). If all BitmapDatas come from the same texture atlas, you should be able to render many thousand objects on slow hardware. Take a look at "TexturePacker", it's a great tool to generate texture atlases. There are also tutorials on the website that explain the importance of texture atlases.

bp74 commented 5 years ago

Example: https://github.com/bp74/StageXL_Samples/tree/master/example/basic/texture_atlas