用途:在 PixiJS v8 中渲染数百到数万个轻量精灵,用单次绘制调用完成,适合粒子效果、子弹弹幕等大量相似对象、且不需要每对象完整功能的场景。粒子共享同一基础纹理,只具备受限的变换属性。
主要能力:ParticleContainer 作为特殊的叶子容器,用 particleChildren 数组存放 Particle 实例,不接受普通显示对象子级;Particle 是轻量结构体,含 x、y、scaleX、scaleY、anchorX、anchorY、rotation、color、texture,并暴露 tint、alpha 设置器。支持 dynamicProperties 控制哪些属性每帧上传 GPU(默认仅 position 动态),支持 roundPixels 与自定义 shader。
使用方式:通过 addParticle 添加、removeParticle 等移除,对应标准容器方法有 addParticleAt、removeParticleAt、removeParticles;批量操作可直接改 particleChildren 再调一次 update() 更快。构造函数可传 texture、particles、boundsArea、dynamicProperties、roundPixels、shader。若需与背景、UI 组合,应把整个 ParticleContainer 包进普通 Container:const world = new Container(); world.addChild(backgroundSprite, particleContainer, uiLayer);
限制:不能给粒子加过滤器、遮罩或逐粒子混合模式,混合模式仅在容器级生效;粒子无嵌套子级与事件;不自动计算边界,ParticleContainer 默认返回空边界 (0,0,0,0),不设置 boundsArea 会在启用剔除时被当作不可见,containsPoint 也总是落空;所有粒子必须共享同一基础纹理源(图集可用,多个不相关纹理不行);标准 children 为空,须用 particleChildren。不要向 ParticleContainer 添加 Sprite,addChild 会抛错,这是相对 v7 的完全重构。若运行时修改静态属性,需调用 container.update() 重新上传。Particle API 为 v8 新增,官方称已可用于生产。