renderChild method
Renders child with batching if eligible, or falls back to individual
rendering if not.
Batching is performed at priority-group boundaries to preserve render order between eligible and non-eligible children. If a child is eligible for batching, its render info is extracted and accumulated into a batch for its atlas image. If not eligible, any pending batches are flushed before rendering the child individually, so that the child renders after any already-accumulated sprites (same priority group).
Implementation
@override
@protected
void renderChild(Canvas canvas, Component child) {
if (!batchingEnabled) {
super.renderChild(canvas, child);
return;
}
// Detect priority-group boundary — flush before crossing it.
final childPriority = child.priority;
if (_currentPriority != null && childPriority != _currentPriority) {
_flushAll(canvas);
}
_currentPriority = childPriority;
final batchInfo = _tryGetBatchInfo(child);
if (batchInfo != null) {
_accumulateChild(child as PositionComponent, batchInfo);
if (child.debugMode) {
for (final hitbox in child.children.whereType<ShapeHitbox>()) {
canvas.save();
canvas.transform2D(child.transform);
hitbox.renderDebugMode(canvas);
canvas.restore();
}
}
} else {
// Non-eligible child: flush any pending batch first so that the child
// renders after already-accumulated sprites (same priority group).
_flushAll(canvas);
super.renderChild(canvas, child);
}
}