|
| 1 | + |
| 2 | +var Class = require('../../utils/Class'); |
| 3 | +var Components = require('../components'); |
| 4 | +var GameObject = require('../GameObject'); |
| 5 | +var Render = require('./ParticleEmitterRender'); |
| 6 | +var Particle = require('./Particle'); |
| 7 | + |
| 8 | +var ParticleEmitter = new Class({ |
| 9 | + |
| 10 | + Extends: GameObject, |
| 11 | + |
| 12 | + Mixins: [ |
| 13 | + Components.Alpha, |
| 14 | + Components.BlendMode, |
| 15 | + Components.Origin, |
| 16 | + Components.RenderTarget, |
| 17 | + Components.ScrollFactor, |
| 18 | + Components.Texture, |
| 19 | + Components.Transform, |
| 20 | + Components.Visible, |
| 21 | + Render |
| 22 | + ], |
| 23 | + |
| 24 | + initialize: |
| 25 | + |
| 26 | + function ParticleEmitter (scene, x, y, texture, frame) |
| 27 | + { |
| 28 | + |
| 29 | + GameObject.call(this, scene, 'ParticleEmitter'); |
| 30 | + |
| 31 | + this.dead = []; |
| 32 | + this.alive = []; |
| 33 | + this.deadQueue = []; |
| 34 | + this.setTexture(texture, frame); |
| 35 | + this.setPosition(x, y); |
| 36 | + this.setSizeToFrame(); |
| 37 | + this.setOrigin(); |
| 38 | + }, |
| 39 | + |
| 40 | + reserve: function (particleCount) |
| 41 | + { |
| 42 | + var dead = this.dead; |
| 43 | + for (var count = 0; particleCount; ++count) |
| 44 | + { |
| 45 | + dead.push(new Particle()); |
| 46 | + } |
| 47 | + }, |
| 48 | + |
| 49 | + getAliveParticleCount: function () |
| 50 | + { |
| 51 | + return this.alive.length; |
| 52 | + }, |
| 53 | + |
| 54 | + getDeadParticleCount: function () |
| 55 | + { |
| 56 | + return this.dead.length; |
| 57 | + }, |
| 58 | + |
| 59 | + getParticleCount: function () |
| 60 | + { |
| 61 | + return this.getAliveParticleCount() + this.getDeadParticleCount(); |
| 62 | + }, |
| 63 | + |
| 64 | + killAll: function () |
| 65 | + { |
| 66 | + var dead = this.dead; |
| 67 | + var alive = this.alive; |
| 68 | + |
| 69 | + while (alive.length > 0) |
| 70 | + { |
| 71 | + dead.push(alive.pop()); |
| 72 | + } |
| 73 | + }, |
| 74 | + |
| 75 | + forEachAlive: function (callback, thisArg) |
| 76 | + { |
| 77 | + var alive = this.alive; |
| 78 | + var length = alive.length; |
| 79 | + |
| 80 | + for (var index = 0; index < length; ++index) |
| 81 | + { |
| 82 | + callback.call(thisArg, alive[index]); |
| 83 | + } |
| 84 | + }, |
| 85 | + |
| 86 | + forEachDead: function (callback, thisArg) |
| 87 | + { |
| 88 | + var dead = this.dead; |
| 89 | + var length = dead.length; |
| 90 | + |
| 91 | + for (var index = 0; index < length; ++index) |
| 92 | + { |
| 93 | + callback.call(thisArg, dead[index]); |
| 94 | + } |
| 95 | + }, |
| 96 | + |
| 97 | + update: function (delta) |
| 98 | + { |
| 99 | + /* Simulation */ |
| 100 | + } |
| 101 | + |
| 102 | +}); |
| 103 | + |
| 104 | +module.exports = ParticleEmitter; |
0 commit comments