Flattened Sprites

This feature was removed in Starling 2 in favor of an automatic render cache. If you're a Starling 2 user (and you should be), please just go on to the next chapter.

Performance-junkies will be happy about the “flatten” method of the Sprite class. It's somewhat similar to the “cacheAsBitmap” property that's available in Flash.

Whenever you call that method, the class will optimize the rendering of its children so that the number of stage3D calls that have to be executed is minimal. That means that everything will be rendered extremely fast. And I mean it — you can expect even complex objects to render as fast as if it was just a single Image.

Of course, this comes at a price: once compiled, you will not be able to see any changes you make to the children. You can still move the sprite, scale it, rotate it, etc. — but not its children. If you make any changes to its children, you have to call “flatten” again to see them.

Thus, this feature is primarily intended for static geometry that does not (or rarely) change. Internally, Starling makes use of this feature when rendering bitmap fonts.

var sprite:Sprite = new Sprite();
sprite.flatten();   // optimize
sprite.unflatten(); // restore normal behaviour

Next section: Asset Management

  manual/flattened_sprites.txt · Last modified: 2016/04/26 15:07 by daniel
Powered by DokuWiki