refactor: more powerful emission
This commit is contained in:
parent
13cff8d3fc
commit
af9924d441
|
@ -83,6 +83,12 @@ export class Emitter extends decorate(Trait) {
|
|||
return hooks;
|
||||
}
|
||||
|
||||
emitParticleJson(json) {
|
||||
return Entity.loadOrInstance(json).then((particle) => {
|
||||
this.entity.emitParticleEntity(particle);
|
||||
});
|
||||
}
|
||||
|
||||
listeners() {
|
||||
return {
|
||||
|
||||
|
@ -151,30 +157,18 @@ export class Emitter extends decorate(Trait) {
|
|||
},
|
||||
|
||||
emitParticleJson: (json) => {
|
||||
return Entity.loadOrInstance(json).then((particle) => {
|
||||
this.entity.emitParticleEntity(particle);
|
||||
return particle;
|
||||
});
|
||||
},
|
||||
|
||||
emitParticle: (key, order = {}) => {
|
||||
const particleJson = this.particles[key]
|
||||
if (!particleJson) {
|
||||
return;
|
||||
}
|
||||
const mergedJson = merge({}, particleJson, order);
|
||||
let {
|
||||
count = 1,
|
||||
rate = 0,
|
||||
} = mergedJson;
|
||||
} = json;
|
||||
if (0 === rate) {
|
||||
for (let i = 0; i < count; ++i) {
|
||||
this.entity.emitParticleJson(mergedJson);
|
||||
this.emitParticleJson(json);
|
||||
}
|
||||
}
|
||||
else {
|
||||
const ticker = new Ticker(rate);
|
||||
this.entity.emitParticleJson(mergedJson);
|
||||
this.emitParticleJson(json);
|
||||
count -= 1;
|
||||
if (count > 0) {
|
||||
const removeEmission = () => {
|
||||
|
@ -185,7 +179,7 @@ export class Emitter extends decorate(Trait) {
|
|||
};
|
||||
this.entity.on('destroy', removeEmission);
|
||||
ticker.on('tick', () => {
|
||||
this.entity.emitParticleJson(mergedJson);
|
||||
this.emitParticleJson(json);
|
||||
if (0 >= --count) {
|
||||
removeEmission();
|
||||
}
|
||||
|
@ -195,6 +189,15 @@ export class Emitter extends decorate(Trait) {
|
|||
}
|
||||
},
|
||||
|
||||
emitParticle: (key, json = {}) => {
|
||||
const particleJson = this.particles[key]
|
||||
if (!particleJson) {
|
||||
return;
|
||||
}
|
||||
const mergedJson = merge({}, particleJson, json);
|
||||
this.entity.emitParticleJson(mergedJson);
|
||||
},
|
||||
|
||||
};
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue
Block a user