Tutorial 13: Static Scene Node
In this tutorial you will learn how to use the static scene node optimization.
Before starting this tutorial be sure to setup an empty project with the Setup Tutorial.
What are static nodes?
Static nodes are nodes that render all their entities on constant textures, and render those textures instead. it acts as an optimizer, because it reduce potentially lots of rendering calls into just a few.
What is it good for?
Sometimes you need to render huge amount of sprites that are pretty much static throughout your game. for example, if you make a game like "Tyrian 2000":
Ness::StaticNodePtr staticNode = scene->create_static_node();
That's it. :)
Now that you know about static scene nodes, it's time to learn about Canvas!
continue to next tutorial -->


staticNode->build();
it's clear that the level background is made out of a tilemap and most of it never change after the level is loaded. in Tyrian there are not too many details in the background so no optimization is required, but what if your game requires thousands or even millions of background sprites?
Static node comes to solve exactly that. the static node basically converts a list of sprites and other renderables into a matrix of textures. it then renders those textures in a fashion similar to a tilemap, thus reducing rendering of thousand of entities into rendering of few textures.
take a look at the following example:
on the left side it's a regular scene node. every tree is a sprite of its own that needs to be rendered. on the right side is the same scene as static node: the trees have been grouped into 3 textures (the bottom right tile was not needed because there were no sprites there), and only 3 sprites are rendered every frame. the result looks the same, but optimized.
As you can understand, there are two downsides to static nodes: once built, the entities cannot be transformed or changed (also means you can't z-order them), and it costs some memory (for the matrix of textures). so use it wisely.
How to create static node
Static nodes are created and behave just like a regular scene node:
you can then add any type of nodes and entities to it and transform them as much as you want. once the static node is ready and you want to build it, i.e. freeze the current state and convert all the entities into the textures matrix, simple call build():
note that without the build the static node will render nothing, and once built, you can no longer change the entities in the static node.
there is a live example of using static nodes here. (just remember ness-engine path is different in the examples then in the tutorials, so change every "../ness-engine/" into "ness-engine/")