Loading...
Loading...
Compare original and translation side by side
Creating and controlling particle effects in Phaser 4 -- ParticleEmitter creation and configuration, emitter ops (value formats), gravity wells, emission and death zones, flow vs burst modes, following game objects, and particle callbacks.
src/gameobjects/particles/在Phaser 4中创建和控制粒子特效——包括ParticleEmitter的创建与配置、发射器操作(值格式)、引力井、发射与消亡区域、流动模式vs爆发模式、跟随游戏对象以及粒子回调。
src/gameobjects/particles/// In a Scene's create() method:
// Basic continuous emitter (flow mode)
const emitter = this.add.particles(400, 300, 'flares', {
frame: 'red',
speed: 200,
lifespan: 2000,
scale: { start: 1, end: 0 },
alpha: { start: 1, end: 0 },
gravityY: 150
});
// One-shot burst (explode mode)
const burst = this.add.particles(400, 300, 'flares', {
frame: 'blue',
speed: { min: 100, max: 300 },
lifespan: 1000,
scale: { start: 0.5, end: 0 },
emitting: false // don't auto-start
});
burst.explode(20); // emit 20 particles at once// 在场景的create()方法中:
// 基础持续发射器(流动模式)
const emitter = this.add.particles(400, 300, 'flares', {
frame: 'red',
speed: 200,
lifespan: 2000,
scale: { start: 1, end: 0 },
alpha: { start: 1, end: 0 },
gravityY: 150
});
// 一次性爆发发射器(爆炸模式)
const burst = this.add.particles(400, 300, 'flares', {
frame: 'blue',
speed: { min: 100, max: 300 },
lifespan: 1000,
scale: { start: 0.5, end: 0 },
emitting: false // 不自动启动
});
burst.explode(20); // 一次性发射20个粒子ParticleEmitterGameObjectthis.add.particles()ParticleEmitterthis.add.particles(x, y, texture, config);
// x, y: world position (both optional, default 0)
// texture: string key or Texture instance
// config: ParticleEmitterConfig object (optional, can call setConfig later)setPosition()setScale()setDepth()setBlendMode()setMask()setScrollFactor()ParticleEmitterGameObjectthis.add.particles()ParticleEmitterthis.add.particles(x, y, texture, config);
// x, y:世界坐标(均为可选参数,默认值0)
// texture:字符串键或Texture实例
// config:ParticleEmitterConfig对象(可选,可后续调用setConfig设置)setPosition()setScale()setDepth()setBlendMode()setMask()setScrollFactor()xyvelocityX/YaccelerationX/YscaleX/YalphaanglerotationtintlifelifeCurrentlifeTbouncedelayCurrentholdCurrentxyvelocityX/YaccelerationX/YscaleX/YalphaanglerotationtintlifelifeCurrentlifeTbouncedelayCurrentholdCurrentx: 400 // static value
x: [100, 200, 300, 400] // random pick from array
x: { min: 100, max: 700 } // random float in range
x: { min: 100, max: 700, int: true } // random integer
x: { random: [100, 700] } // random integer shorthand
scale: { start: 0, end: 1 } // ease over lifetime (default linear)
scale: { start: 0, end: 1, ease: 'bounce.out' } // custom ease
scale: { start: 4, end: 0.5, random: true } // random start, ease to end
x: { values: [50, 500, 200, 800], interpolation: 'catmull' } // interpolation
x: { steps: 32, start: 0, end: 576 } // stepped sequential
x: { steps: 32, start: 0, end: 576, yoyo: true } // stepped with yoyo
x: { // custom callbacks
onEmit: (particle, key, t, value) => value,
onUpdate: (particle, key, t, value) => value
}
x: (particle, key, t, value) => value + 50 // emit-time callback shorthandangledelayholdlifespanquantityspeedXspeedYaccelerationX/YalphabouncemaxVelocityX/YmoveToX/YrotatescaleX/Ytintxyx: 400 // 静态值
x: [100, 200, 300, 400] // 从数组中随机选取
x: { min: 100, max: 700 } // 范围内的随机浮点数
x: { min: 100, max: 700, int: true } // 随机整数
x: { random: [100, 700] } // 随机整数简写
scale: { start: 0, end: 1 } // 生命周期内缓动(默认线性)
scale: { start: 0, end: 1, ease: 'bounce.out' } // 自定义缓动
scale: { start: 4, end: 0.5, random: true } // 随机起始值,缓动至结束值
x: { values: [50, 500, 200, 800], interpolation: 'catmull' } // 插值
x: { steps: 32, start: 0, end: 576 } // 分步序列
x: { steps: 32, start: 0, end: 576, yoyo: true } // 带往返的分步序列
x: { // 自定义回调
onEmit: (particle, key, t, value) => value,
onUpdate: (particle, key, t, value) => value
}
x: (particle, key, t, value) => value + 50 // 发射时回调简写angledelayholdlifespanquantityspeedXspeedYaccelerationX/YalphabouncemaxVelocityX/YmoveToX/YrotatescaleX/Ytintxyfrequency >= 0quantityfrequencyfrequency: 0emitting: truefrequency = -1emitter.flow(100, 5); // 5 particles every 100ms
emitter.flow(100, 5, 50); // auto-stop after 50 total
emitter.explode(30, 200, 400); // burst 30 at position
emitter.explode(30); // burst at emitter positionfrequency >= 0frequencyquantityfrequency: 0emitting: truefrequency = -1emitter.flow(100, 5); // 每100毫秒发射5个粒子
emitter.flow(100, 5, 50); // 发射满50个后自动停止
emitter.explode(30, 200, 400); // 在指定位置爆发30个粒子
emitter.explode(30); // 在发射器位置爆发粒子// Scale and alpha with custom easing
this.add.particles(400, 300, 'spark', {
lifespan: 2000,
speed: 100,
scale: { start: 1, end: 0, ease: 'power2' },
alpha: { start: 1, end: 0, ease: 'cubic.in' }
});// 带自定义缓动的缩放和透明度
this.add.particles(400, 300, 'spark', {
lifespan: 2000,
speed: 100,
scale: { start: 1, end: 0, ease: 'power2' },
alpha: { start: 1, end: 0, ease: 'cubic.in' }
});colortintthis.add.particles(400, 300, 'spark', {
lifespan: 2000, speed: 100, scale: { start: 0.5, end: 0 },
color: [0xfacc22, 0xf89800, 0xf83600, 0x9f0404], colorEase: 'quad.out'
});colortintthis.add.particles(400, 300, 'spark', {
lifespan: 2000, speed: 100, scale: { start: 0.5, end: 0 },
color: [0xfacc22, 0xf89800, 0xf83600, 0x9f0404], colorEase: 'quad.out'
});this.add.particles(400, 300, 'spark', { tint: 0xff0000 }); // static
this.add.particles(400, 300, 'spark', { tint: { start: 0xffffff, end: 0xff0000 } }); // over lifetimethis.add.particles(400, 300, 'spark', { tint: 0xff0000 }); // 静态着色
this.add.particles(400, 300, 'spark', { tint: { start: 0xffffff, end: 0xff0000 } }); // 生命周期内渐变GravityWellpowerconst emitter = this.add.particles(400, 300, 'spark', {
speed: 100, lifespan: 4000, scale: { start: 0.4, end: 0 }, quantity: 2
});
const well = emitter.createGravityWell({
x: 400, y: 300, power: 2, epsilon: 100, gravity: 50
});
// Update at runtime
well.x = 300;
well.power = -1; // negative = repel
// Or create manually and add
const well2 = new Phaser.GameObjects.Particles.GravityWell(500, 200, 3, 100, 50);
emitter.addParticleProcessor(well2);
emitter.removeParticleProcessor(well2);GravityWellpowerconst emitter = this.add.particles(400, 300, 'spark', {
speed: 100, lifespan: 4000, scale: { start: 0.4, end: 0 }, quantity: 2
});
const well = emitter.createGravityWell({
x: 400, y: 300, power: 2, epsilon: 100, gravity: 50
});
// 运行时更新
well.x = 300;
well.power = -1; // 负值表示推开粒子
// 或者手动创建并添加
const well2 = new Phaser.GameObjects.Particles.GravityWell(500, 200, 3, 100, 50);
emitter.addParticleProcessor(well2);
emitter.removeParticleProcessor(well2);RandomZonegetRandomPoint(point)// Using built-in geometry
this.add.particles(400, 300, 'spark', {
speed: 50, lifespan: 2000,
emitZone: { type: 'random', source: new Phaser.Geom.Circle(0, 0, 100) }
});
// Custom source object (any object with getRandomPoint)
emitter.addEmitZone({
type: 'random',
source: {
getRandomPoint: (point) => {
const a = Math.random() * Math.PI * 2;
point.x = Math.cos(a) * 100;
point.y = Math.sin(a) * 50;
return point;
}
}
});RandomZonegetRandomPoint(point)// 使用内置几何形状
this.add.particles(400, 300, 'spark', {
speed: 50, lifespan: 2000,
emitZone: { type: 'random', source: new Phaser.Geom.Circle(0, 0, 100) }
});
// 自定义源对象(任何拥有getRandomPoint方法的对象)
emitter.addEmitZone({
type: 'random',
source: {
getRandomPoint: (point) => {
const a = Math.random() * Math.PI * 2;
point.x = Math.cos(a) * 100;
point.y = Math.sin(a) * 50;
return point;
}
}
});EdgeZonegetPoints(quantity, stepRate)this.add.particles(400, 300, 'spark', {
lifespan: 1500, speed: 20,
emitZone: {
type: 'edge',
source: new Phaser.Geom.Circle(0, 0, 150),
quantity: 48, // number of points on edge (use 0 with stepRate instead)
yoyo: false, // reverse direction at ends
seamless: true // remove duplicate endpoint
}
});
// Or add post-creation with any source that has getPoints
emitter.addEmitZone({ type: 'edge', source: geom, quantity: 50, yoyo: false, seamless: true });emitZoneaddEmitZone()totalthis.add.particles(400, 300, 'spark', {
emitZone: [
{ type: 'random', source: new Phaser.Geom.Circle(0, 0, 50) },
{ type: 'random', source: new Phaser.Geom.Circle(200, 0, 50) }
]
});EdgeZonegetPoints(quantity, stepRate)this.add.particles(400, 300, 'spark', {
lifespan: 1500, speed: 20,
emitZone: {
type: 'edge',
source: new Phaser.Geom.Circle(0, 0, 150),
quantity: 48, // 边缘上的点数量(也可设为0并使用stepRate)
yoyo: false, // 是否在端点反向
seamless: true // 是否移除重复的端点
}
});
// 或者创建后添加任何拥有getPoints方法的源对象
emitter.addEmitZone({ type: 'edge', source: geom, quantity: 50, yoyo: false, seamless: true });emitZoneaddEmitZone()totalthis.add.particles(400, 300, 'spark', {
emitZone: [
{ type: 'random', source: new Phaser.Geom.Circle(0, 0, 50) },
{ type: 'random', source: new Phaser.Geom.Circle(200, 0, 50) }
]
});DeathZonecontains(x, y)// Kill particles entering a rectangle
this.add.particles(400, 100, 'spark', {
speed: 200, lifespan: 5000, gravityY: 100,
deathZone: { type: 'onEnter', source: new Phaser.Geom.Rectangle(300, 400, 200, 50) }
});
// Kill particles leaving a circle (confine to area)
this.add.particles(400, 300, 'spark', {
speed: 100, lifespan: 5000,
deathZone: { type: 'onLeave', source: new Phaser.Geom.Circle(400, 300, 150) }
});
// Custom death zone source (any object with contains)
emitter.addDeathZone({
type: 'onEnter',
source: { contains: (x, y) => x > 600 && y > 400 }
});DeathZonecontains(x, y)// 销毁进入矩形区域的粒子
this.add.particles(400, 100, 'spark', {
speed: 200, lifespan: 5000, gravityY: 100,
deathZone: { type: 'onEnter', source: new Phaser.Geom.Rectangle(300, 400, 200, 50) }
});
// 销毁离开圆形区域的粒子(限制在区域内)
this.add.particles(400, 300, 'spark', {
speed: 100, lifespan: 5000,
deathZone: { type: 'onLeave', source: new Phaser.Geom.Circle(400, 300, 150) }
});
// 自定义消亡区域源对象(任何拥有contains方法的对象)
emitter.addDeathZone({
type: 'onEnter',
source: { contains: (x, y) => x > 600 && y > 400 }
});const player = this.add.sprite(100, 100, 'player');
const emitter = this.add.particles(0, 0, 'spark', {
speed: 50, lifespan: 800, scale: { start: 0.5, end: 0 }
});
emitter.startFollow(player); // follow position
emitter.startFollow(player, 10, -20); // with offset
emitter.startFollow(player, 0, 0, true); // track visibility too
emitter.stopFollow();
// Or via config:
this.add.particles(0, 0, 'spark', { follow: player, followOffset: { x: 0, y: -20 } });const player = this.add.sprite(100, 100, 'player');
const emitter = this.add.particles(0, 0, 'spark', {
speed: 50, lifespan: 800, scale: { start: 0.5, end: 0 }
});
emitter.startFollow(player); // 跟随位置
emitter.startFollow(player, 10, -20); // 带偏移量
emitter.startFollow(player, 0, 0, true); // 同时跟踪可见性
emitter.stopFollow();
// 或者通过配置:
this.add.particles(0, 0, 'spark', { follow: player, followOffset: { x: 0, y: -20 } });// Via config
const emitter = this.add.particles(400, 300, 'spark', {
speed: 100, lifespan: 2000,
emitCallback: (particle, emitter) => { /* on emit */ },
deathCallback: (particle) => { /* on death */ }
});
// Or set after creation
emitter.onParticleEmit((particle, emitter) => { /* ... */ });
emitter.onParticleDeath((particle) => { /* ... */ });
// Iterate alive/dead particles
emitter.forEachAlive((particle, emitter) => { /* particle.x, particle.lifeT */ });// 通过配置
const emitter = this.add.particles(400, 300, 'spark', {
speed: 100, lifespan: 2000,
emitCallback: (particle, emitter) => { /* 发射时执行 */ },
deathCallback: (particle) => { /* 消亡时执行 */ }
});
// 或者创建后设置
emitter.onParticleEmit((particle, emitter) => { /* ... */ });
emitter.onParticleDeath((particle) => { /* ... */ });
// 遍历存活/消亡的粒子
emitter.forEachAlive((particle, emitter) => { /* particle.x, particle.lifeT */ });// Auto-stop after 3 seconds (alive particles continue until they expire)
this.add.particles(400, 300, 'spark', { speed: 100, duration: 3000 });
// Emit exactly 50 particles then stop
this.add.particles(400, 300, 'spark', { speed: 100, stopAfter: 50 });
// Pre-warm: fast-forward 2 seconds so particles visible on first frame
this.add.particles(400, 300, 'spark', { speed: 100, lifespan: 2000, advance: 2000 });
// Or manually: emitter.fastForward(2000, 50);// 3秒后自动停止(存活的粒子会继续直到生命周期结束)
this.add.particles(400, 300, 'spark', { speed: 100, duration: 3000 });
// 恰好发射50个粒子后停止
this.add.particles(400, 300, 'spark', { speed: 100, stopAfter: 50 });
// 预预热:快进2秒,使第一帧就可见粒子
this.add.particles(400, 300, 'spark', { speed: 100, lifespan: 2000, advance: 2000 });
// 或者手动操作:emitter.fastForward(2000, 50);this.add.particles(400, 300, 'spark', {
speed: 200, lifespan: 5000, bounce: 0.8,
bounds: { x: 100, y: 100, width: 600, height: 400 },
collideLeft: true, collideRight: true, collideTop: true, collideBottom: true
});
// Or: emitter.addParticleBounds(100, 100, 600, 400);this.add.particles(400, 300, 'spark', {
speed: 200, lifespan: 5000, bounce: 0.8,
bounds: { x: 100, y: 100, width: 600, height: 400 },
collideLeft: true, collideRight: true, collideTop: true, collideBottom: true
});
// 或者:emitter.addParticleBounds(100, 100, 600, 400);// Random frame per particle
this.add.particles(400, 300, 'flares', { frame: ['red', 'green', 'blue'] });
// Sequential frames cycling through with quantity per frame
this.add.particles(400, 300, 'flares', {
frame: { frames: ['red', 'green', 'blue'], cycle: true, quantity: 4 }
});
// Particle animation (plays anim over particle lifetime)
this.add.particles(400, 300, 'explosion', { anim: 'explode_anim', lifespan: 1000 });
// Multiple anims, randomly assigned
this.add.particles(400, 300, 'sheet', {
anim: { anims: ['fire', 'smoke'], cycle: false, quantity: 1 }
});// 每个粒子随机选取帧
this.add.particles(400, 300, 'flares', { frame: ['red', 'green', 'blue'] });
// 按顺序循环帧,每帧指定数量的粒子
this.add.particles(400, 300, 'flares', {
frame: { frames: ['red', 'green', 'blue'], cycle: true, quantity: 4 }
});
// 粒子动画(在粒子生命周期内播放动画)
this.add.particles(400, 300, 'explosion', { anim: 'explode_anim', lifespan: 1000 });
// 多个动画,随机分配
this.add.particles(400, 300, 'sheet', {
anim: { anims: ['fire', 'smoke'], cycle: false, quantity: 1 }
});this.add.particles(400, 300, 'spark', { sortProperty: 'y', sortOrderAsc: true });
// Or: sortCallback: (a, b) => a.y - b.ythis.add.particles(400, 300, 'spark', { sortProperty: 'y', sortOrderAsc: true });
// 或者:sortCallback: (a, b) => a.y - b.yParticleProcessorupdate(particle, delta, step, t)class WindProcessor extends Phaser.GameObjects.Particles.ParticleProcessor {
constructor (windX, windY) {
super(0, 0);
this.windX = windX;
this.windY = windY;
}
update (particle, delta, step, t) {
particle.velocityX += this.windX * step;
particle.velocityY += this.windY * step;
}
}
emitter.addParticleProcessor(new WindProcessor(0.5, 0));ParticleProcessorupdate(particle, delta, step, t)class WindProcessor extends Phaser.GameObjects.Particles.ParticleProcessor {
constructor (windX, windY) {
super(0, 0);
this.windX = windX;
this.windY = windY;
}
update (particle, delta, step, t) {
particle.velocityX += this.windX * step;
particle.velocityY += this.windY * step;
}
}
emitter.addParticleProcessor(new WindProcessor(0.5, 0));ParticleupdateparticleClassclass TrailParticle extends Phaser.GameObjects.Particles.Particle {
update (delta, step, processors) {
const result = super.update(delta, step, processors);
this.alpha = this.lifeT; // custom: alpha matches life progress
return result; // must return true if particle is still alive
}
}
this.add.particles(400, 300, 'spark', {
particleClass: TrailParticle,
speed: 100, lifespan: 2000
});ParticleupdateparticleClassclass TrailParticle extends Phaser.GameObjects.Particles.Particle {
update (delta, step, processors) {
const result = super.update(delta, step, processors);
this.alpha = this.lifeT; // 自定义:透明度与生命周期进度匹配
return result; // 必须返回true表示粒子仍存活
}
}
this.add.particles(400, 300, 'spark', {
particleClass: TrailParticle,
speed: 100, lifespan: 2000
});| Property | Type | Default | Description |
|---|---|---|---|
| boolean | | False = emitter does not update at all |
| boolean | | False = no new particles (alive ones still update) |
| string/number | | Blend mode for rendering |
| number | | ms between flow cycles; 0 = every frame; -1 = explode |
| number | | Gravity in px/s^2 |
| number | | Hard limit on total particle objects (0 = unlimited) |
| number | | Max alive particles at once (0 = unlimited) |
| number | | Auto-stop after ms (0 = forever) |
| number | | Auto-stop after N particles emitted (0 = unlimited) |
| number | | Fast-forward on creation (ms) |
| boolean | | True = speed+angle; false = speedX/speedY |
| boolean | | New particles render on top |
| number | | Time multiplier for updates |
| Vector2Like | | Object to follow |
| Vector2Like | Offset from follow target | |
| boolean | | Match follow target's visibility |
| number | Pre-allocate particle objects | |
| function | | Custom particle class |
| string | Particle property to sort by | |
| boolean | Sort ascending if true |
| 属性 | 类型 | 默认值 | 描述 |
|---|---|---|---|
| boolean | | 设为false时,发射器完全不更新 |
| boolean | | 设为false时,不再发射新粒子(存活的粒子仍会更新) |
| string/number | | 渲染混合模式 |
| number | | 流动周期间隔(毫秒);0表示每帧发射;-1表示爆发模式 |
| number | | 重力加速度(像素/秒²) |
| number | | 粒子对象总数上限(0表示无限制) |
| number | | 同时存活的粒子数量上限(0表示无限制) |
| number | | 自动停止前的持续时长(毫秒);0表示永久 |
| number | | 自动停止前发射的粒子总数;0表示无限制 |
| number | | 创建时快进的时长(毫秒) |
| boolean | | 设为true时使用speed+angle;设为false时使用speedX/speedY |
| boolean | | 新粒子渲染在最上层 |
| number | | 更新的时间乘数 |
| Vector2Like | | 要跟随的对象 |
| Vector2Like | 跟随目标的偏移量 | |
| boolean | | 是否匹配跟随目标的可见性 |
| number | 预分配的粒子对象数量 | |
| function | | 自定义粒子类 |
| string | 用于排序的粒子属性 | |
| boolean | 设为true时升序排序 |
| Property | Default | E/U | Description |
|---|---|---|---|
| | E+U | Particle offset from emitter |
| | E | Radial speed (sets speedX, deactivates speedY) |
| | E | Directional speed (sets radial=false) |
| | E | Emission angle in degrees |
| | E+U | Uniform scale (sets scaleX, deactivates scaleY) |
| | E+U | Non-uniform scale |
| | E+U | Alpha transparency |
| | E+U | Rotation in degrees |
| | E+U | Tint color (WebGL) |
| E+U | Color array to interpolate (overrides tint) | |
| Ease for color interpolation | ||
| | E | Lifetime in ms |
| | E | Delay before visible (ms) |
| | E | Hold at end of life before dying (ms) |
| | E | Particles per flow cycle |
| | E+U | Acceleration (px/s^2) |
| | E+U | Max velocity |
| | E+U | Bounce restitution (0-1) |
| | E+U | Target position (overrides angle/speed) |
| 属性 | 默认值 | E/U | 描述 |
|---|---|---|---|
| | E+U | 粒子相对于发射器的偏移量 |
| | E | 径向速度(设置speedX,停用speedY) |
| | E | 定向速度(设置radial=false) |
| | E | 发射角度(度) |
| | E+U | 统一缩放(设置scaleX,停用scaleY) |
| | E+U | 非统一缩放 |
| | E+U | 透明度 |
| | E+U | 旋转角度(度) |
| | E+U | 着色颜色(WebGL) |
| E+U | 要插值的颜色数组(会覆盖tint) | |
| 颜色插值的缓动方式 | ||
| | E | 粒子生命周期(毫秒) |
| | E | 粒子可见前的延迟(毫秒) |
| | E | 生命周期结束后保持可见的时长(毫秒) |
| | E | 每个流动周期发射的粒子数量 |
| | E+U | 加速度(像素/秒²) |
| | E+U | 最大速度 |
| | E+U | 弹跳恢复系数(0-1) |
| | E+U | 目标位置(会覆盖angle/speed) |
| Config Key | Type | Properties |
|---|---|---|
| object or array | |
| ||
| object or array | |
| object | |
| 配置键 | 类型 | 属性 |
|---|---|---|
| object或array | |
| ||
| object或array | |
| object | |
ParticleEmitter| Event | String | Callback Args | When |
|---|---|---|---|
| | | |
| | | |
| | | Final alive particle dies after emitter has stopped |
| | | |
| | | A death zone kills a particle |
emitter.on('stop', (emitter) => { /* stopped emitting */ });
emitter.on('complete', (emitter) => { /* all particles dead */ });
emitter.on('deathzone', (emitter, particle, zone) => { /* ... */ });ParticleEmitter| 事件 | 字符串 | 回调参数 | 触发时机 |
|---|---|---|---|
| | | 调用 |
| | | 调用 |
| | | 发射器停止后,最后一个存活粒子消亡时 |
| | | 调用 |
| | | 消亡区域销毁粒子时 |
emitter.on('stop', (emitter) => { /* 停止发射 */ });
emitter.on('complete', (emitter) => { /* 所有粒子消亡 */ });
emitter.on('deathzone', (emitter, particle, zone) => { /* ... */ });start(advance?, duration?)stop(kill?)pause()resume()flow(frequency, count?, stopAfter?)explode(count?, x?, y?)emitParticleAt(x?, y?, count?)emitParticle(count?, x?, y?)fastForward(time, delta?)setConfig(config)updateConfig(config)startFollow(target, offX?, offY?, trackVisible?)stopFollow()addEmitZone(config)removeEmitZone(zone)clearEmitZones()addDeathZone(config)removeDeathZone(zone)clearDeathZones()createGravityWell(config)addParticleProcessor(processor)removeParticleProcessor(processor)getProcessors()addParticleBounds(x, y, w, h, collideL?, collideR?, collideT?, collideB?)onParticleEmit(cb, ctx?)onParticleDeath(cb, ctx?)killAll()forEachAlive(cb, ctx?)forEachDead(cb, ctx?)getAliveParticleCount()getDeadParticleCount()getParticleCount()atLimit()reserve(count)setParticleSpeed(x, y?)setParticleScale(x, y?)setParticleGravity(x, y)setParticleAlpha(value)setParticleTint(value)setParticleLifespan(value)setEmitterAngle(value)setQuantity(qty)setFrequency(freq, qty?)setRadial(value)setEmitterFrame(frames, random?, qty?)setAnim(anims, random?, qty?)setSortProperty(property, ascending?)setSortCallback(callback)depthSort()getBounds(padding?, advance?, delta?, output?)overlap(target)start(advance?, duration?)stop(kill?)pause()resume()flow(frequency, count?, stopAfter?)explode(count?, x?, y?)emitParticleAt(x?, y?, count?)emitParticle(count?, x?, y?)fastForward(time, delta?)setConfig(config)updateConfig(config)startFollow(target, offX?, offY?, trackVisible?)stopFollow()addEmitZone(config)removeEmitZone(zone)clearEmitZones()addDeathZone(config)removeDeathZone(zone)clearDeathZones()createGravityWell(config)addParticleProcessor(processor)removeParticleProcessor(processor)getProcessors()addParticleBounds(x, y, w, h, collideL?, collideR?, collideT?, collideB?)onParticleEmit(cb, ctx?)onParticleDeath(cb, ctx?)killAll()forEachAlive(cb, ctx?)forEachDead(cb, ctx?)getAliveParticleCount()getDeadParticleCount()getParticleCount()atLimit()reserve(count)setParticleSpeed(x, y?)setParticleScale(x, y?)setParticleGravity(x, y)setParticleAlpha(value)setParticleTint(value)setParticleLifespan(value)setEmitterAngle(value)setQuantity(qty)setFrequency(freq, qty?)setRadial(value)setEmitterFrame(frames, random?, qty?)setAnim(anims, random?, qty?)setSortProperty(property, ascending?)setSortCallback(callback)depthSort()getBounds(padding?, advance?, delta?, output?)overlap(target)| Property/Method | Description |
|---|---|
| World position of the well |
| Force strength (negative to repel) |
| Min distance for force calc (default 100) |
| Gravitational constant (default 50) |
| Enable/disable processing (inherited from ParticleProcessor) |
new GravityWell(x, y, power, epsilon, gravity)new GravityWell(config){ x, y, power, epsilon, gravity }| 属性/方法 | 描述 |
|---|---|
| 引力井的世界坐标 |
| 力的强度(负值表示推开粒子) |
| 力计算的最小距离(默认100) |
| 引力常数(默认50) |
| 启用/禁用处理器(继承自ParticleProcessor) |
new GravityWell(x, y, power, epsilon, gravity)new GravityWell(config){ x, y, power, epsilon, gravity }this.add.particles()ParticleEmitterspeedspeedXspeedYspeedspeedXspeedYradial: falsescalescaleXscaleYscalecolortintcolormoveToXmoveToYanglespeedemittingactiveemitting: falseactive: falsestopcomplete'stop''complete'frequency: 0emitting: falsefrequency: -1explode()holdholdadvancereserve(count)reserve()reservegetRandomPoint(point)getPoints(quantity, stepRate)contains(x, y)maxParticlesmaxAliveParticlesframethis.add.particles()ParticleEmitterspeedspeedXspeedYspeedspeedXspeedYradial: falsescalescaleXscaleYscalecolortintcolormoveToXmoveToYanglespeedemittingactiveemitting: falseactive: falsestopcomplete'stop''complete'frequency: 0emitting: falsefrequency: -1explode()holdholdadvancereserve(count)reserve()reservegetRandomPoint(point)getPoints(quantity, stepRate)contains(x, y)maxParticlesmaxAliveParticlesframereferences/REFERENCE.mdsrc/gameobjects/particles/ParticleEmitter.jssrc/gameobjects/particles/Particle.jssrc/gameobjects/particles/zones/references/REFERENCE.mdsrc/gameobjects/particles/ParticleEmitter.jssrc/gameobjects/particles/Particle.jssrc/gameobjects/particles/zones/