In the process of project development, summed up the Starling performance optimization scheme:
1. do not frequently read the width height of the display object: the GetBounds () method of the display object is called when the wide-height property is called, and the method iterates through all the child objects of the object and recalculates the width height. When using the wide-height attribute frequently, it is best to save the width to the variable if there is no special need, instead of directly reading the width-height attribute with the value saved by the variable.
2. Flat Sprites:Starling will traverse all objects at each frame to check their status, upload their data to the GPU for re-rendering, call the Sprite's Flatten () method, Gup will not re-upload the object to render, When you need to update the display object, you can call its Unflatten () method.
3. Quadbatch:Quadbatch class is a flat container, every time you add an object to the container, it will dispatch a "ADDED" and "Added_to_stage" event, when you have a lot of objects, it is also a small cost, Especially when you use textures that are from the same texture Atlas, Quadbatch is more efficient, and it can only add an instance of an image, Quad, or Quadbatch class.
4. reduced event Distribution:Starling display objects will be dispatched a "ADDED" and "Added_to_stage" event when the add is on the stage, and "Removeed" and "Removeed _to_" are also distributed when removed STAGE "events, many times these events do not make sense to us, we can modify the Starling display object or customize a display object, rewrite its Addchild method, the event distribution removed, reduce unnecessary overhead.
5. clean-up: when destroying an object, ensure that the object and sub-objects are destroyed thoroughly, and the event is removed cleanly, Starling frequently created objects are not destroyed will cause the resource exceeded the upper limit error, resulting in a program crash.
6. Mixed Mode: If there is a completely opaque rectangular texture, we can let the GPU disable those texture blending. This is especially useful for large background images. Set object.blendmode = Blendmode.none;
7. touchenable not clickable: set touchenable= false for objects that do not need to accept events, and reduce unnecessary time to monitor and distribute.
8. Use bitmap fonts: replace system fonts with bitmap fonts, and performance will multiply.
9. Texture Atlas:Starling uses the painter algorithm to process the display list, and if all of these textures are loaded from a single atlas, Starling can do all the drawing in one call. A texture atlas that supports a maximum 2048*2048 size in starling.
no visible discard rendering: When the display object is not in the screen or not within the visual range, we can remove it or set the Visible property to False, which can greatly reduce the pressure of GPU rendering and improve performance.
image instead of button: use the image as much as possible without using the button, which is better at rendering speed and overhead than the latter.
Basic AS3 Performance optimizations: use for to override for each, do not create objects frequently in the for loop, assign values to the length property of the array to variables, rather than frequent calls to AS3 good coding habits.
use ATF textures: This format is very powerful, you can use the command line to convert a PNG file to an ATF file (contains file types for different devices Android (ETC1), IOS (PVRTC), Windows and MacOS (DXT) )。 Flash player and Air automatically choose the right format based on the operating platform, and the ATF has the advantage of faster rendering speed, smaller memory footprint, faster upload speed and smaller application volume, and is highly recommended.
(Note: Red is an important optimization scheme)