用途:Container 是 PixiJS v8 场景图中的通用节点,用于承载子节点,并对整个子树施加变换、alpha、tint 和混合模式。每个显示对象要么是正在构建分支的 Container,要么是嵌套其中的叶子对象(Sprite、Graphics、Text、Mesh)。
主要能力:通过构造选项(如 x、y、scale、rotation、alpha、visible、tint、blendMode、sortableChildren、isRenderGroup、origin、boundsArea)批量设置属性。支持 addChild、addChildAt、swapChildren、setChildIndex、removeChild、removeChildren 等子节点管理;position、scale、pivot、skew 为 ObservablePoint,rotation 与 angle 互为别名;alpha 和 tint 向下相乘。sortableChildren 为 true 时按 zIndex 在下次渲染前重排子节点。
getBounds() 返回 Bounds 对象,需要 Rectangle 时读取 .rectangle;toGlobal、toLocal、getGlobalPosition 用于坐标转换;setSize 一次性调整缩放使边界适配目标像素尺寸。事件包括 childAdded、childRemoved、added、removed、destroyed、visibleChanged。onRender 可做每帧更新。getChildByLabel、getChildrenByLabel、getLocalBounds、removeFromParent 用于查找与移除。destroy({children, texture, textureSource}) 支持递归销毁。
使用方式:先创建 Container 并传入选项,再向其中添加叶子对象,最后把容器加入 app.stage。需要分组时始终用 Container 包裹 Sprite 等叶子节点。
限制:不应给叶子对象添加子节点,目前会记录弃用警告,未来将报错;不要同时设置 pivot 和 origin;v8 用 label 替代 name、用 cacheAsTexture() 替代 cacheAsBitmap;使用 cacheAsTexture 时销毁前需调用 cacheAsTexture(false)。该技能假定已熟悉 pixijs-scene-core-concepts,官方具体平台与版本细节暂未提供。