MCPcopy Create free account
hub / github.com/esengine/esengine / addChildAt

Function addChildAt

packages/fairygui/src/display/DisplayObject.ts:310–330  ·  view source on GitHub ↗

* Add a child at specific index * 在指定位置添加子显示对象

(child: DisplayObject, index: number)

Source from the content-addressed store, hash-verified

308 * 在指定位置添加子显示对象
309 */
310 public addChildAt(child: DisplayObject, index: number): void {
311 if (child._parent === this) {
312 this.setChildIndex(child, index);
313 return;
314 }
315
316 if (child._parent) {
317 child._parent.removeChild(child);
318 }
319
320 index = Math.max(0, Math.min(index, this._children.length));
321 this._children.splice(index, 0, child);
322 child._parent = this;
323 child.markTransformDirty();
324
325 // Dispatch addedToStage event if this is on stage
326 // 如果当前对象在舞台上,分发 addedToStage 事件
327 if (this._stage !== null) {
328 this.setChildStage(child, this._stage);
329 }
330 }
331
332 /**
333 * Set stage for child and its descendants, dispatch events

Callers

nothing calls this directly

Calls 4

setChildIndexMethod · 0.80
removeChildMethod · 0.45
maxMethod · 0.45
minMethod · 0.45

Tested by

no test coverage detected