Performance: Sorting layers and order
MEDIUM IMPACT
This affects how quickly and smoothly the game renders objects in the correct visual order, impacting frame rate and visual stability.
Assign sorting layers and orders once during initialization or only when necessary, e.g., on state change.
foreach (var sprite in sprites) { sprite.sortingOrder = CalculateOrder(sprite); sprite.sortingLayerName = "DynamicLayer"; }
| Pattern | DOM Operations | Reflows | Paint Cost | Verdict |
|---|---|---|---|---|
| Frequent sorting layer/order changes per frame | N/A | Multiple re-sorts per frame | High GPU redraw cost | [X] Bad |
| Sorting layers and orders set once or on change | N/A | Single sort on update | Low GPU redraw cost | [OK] Good |