void addChild(Node child)

Adds a child to this node.

The same node cannot be added to multiple nodes.

addChild(new Sprite(myImage));

Source

void addChild(Node child) {
  assert(child != null);
  assert(child._parent == null);

  assert(() {
    Node node = this;
    while (node.parent != null)
      node = node.parent;
    assert(node != child); // indicates we are about to create a cycle
    return true;
  });

  _childrenNeedSorting = true;
  _children.add(child);
  child._parent = this;
  child._spriteBox = this._spriteBox;
  _childrenLastAddedOrder += 1;
  child._addedOrder = _childrenLastAddedOrder;
  if (_spriteBox != null) _spriteBox._registerNode(child);
}