spawn method

Node spawn({
  1. Node? parent,
  2. Matrix4? transform,
  3. void onSpawn(
    1. Node node
    )?,
})

Acquires a node from the pool and attaches it to parent.

Implementation

Node spawn({
  Node? parent,
  vm.Matrix4? transform,
  void Function(Node node)? onSpawn,
}) {
  final Node node;
  if (_idle.isNotEmpty) {
    node = _idle.removeLast();
  } else {
    node = factory();
  }

  if (transform != null) {
    node.localTransform = transform.clone();
  }

  if (parent != null) {
    parent.add(node);
  }

  _active.add(node);
  onSpawn?.call(node);
  return node;
}