用途:Container 是 PixiJS v8 场景图的通用节点,用于分组、定位和变换显示对象,可对整棵子树应用变换、alpha、tint 与混合模式。Sprite、Graphics、Text、Mesh 等为叶子节点,需要分组时应包在 Container 中。
主要能力:构造选项支持 label、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 互为别名;zIndex 配合 sortableChildren 控制渲染顺序;getBounds 返回 Bounds(需 Rectangle 时读 .rectangle),toGlobal/toLocal 做坐标转换;setSize 一次调整尺寸;支持 childAdded、childRemoved、added、removed、destroyed、visibleChanged 事件与 onRender 逐帧回调;destroy 可递归销毁子级与纹理资源。
用法要点:new Container({...}) 创建,addChild 添加子级,sortableChildren 为 true 时按 zIndex 重排;isRenderGroup 将子树提升为渲染组,宜用于稳定子树并先做性能分析;origin 与 pivot 不建议同时设置。
限制:叶子对象不应添加子级,否则会记录弃用警告;getBounds 不返回 Rectangle;v8 中 cacheAsBitmap 已改为 cacheAsTexture() 方法,name 已改为 label;destroy 后位置、缩放等字段已被置空,需在调用前保存数据。其余细节暂未提供。