-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathparticles.js
More file actions
42 lines (35 loc) · 1.28 KB
/
particles.js
File metadata and controls
42 lines (35 loc) · 1.28 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
pc.script.create('particles', function (context) {
var Particles = function (entity) {
this.entity = entity;
this.index = 0;
};
Particles.prototype = {
initialize: function () {
context.graphicsDevice.programLib.register("particle_old", pc.gfx.programlib.particle_old)
this.effects = {};
var children = this.entity.getChildren();
for (var i=0; i<children.length; i++) {
var child = children[i];
if (!this.effects[child.getName()]) {
this.effects[child.getName()] = {
entities: [],
index: 0
};
}
this.effects[child.getName()].entities.push(child);
child.enabled = false;
}
},
spawn: function (name, position) {
var effects = this.effects[name];
if (effects) {
var entity = effects.entities[effects.index];
entity.setPosition(position);
entity.enabled = true;
entity.script.particle_emitter.resetEffect();
effects.index = (effects.index + 1) % effects.entities.length;
}
}
};
return Particles;
});