RPG Maker Forums

Plugin


Particle Engine - Core


Description


Extensible particle engine, that creates effects by applying behaviours to particle objects.


Author


Iavra


How to Use


The following script call creates a sample emitter, that displays a bunch of particles wandering around the screen:



var emitter = new IAVRA.PARTICLE.Emitter()
.setCounter({
start: function(emitter) {},
update: function(emitter) { return 1; }
})
.addBehaviour({
setup: function(emitter, particle) {
particle.texture = PIXI.Texture.fromImage('img/particle.png');
particle.position.set(Graphics.width / 2, Graphics.height / 2);
particle.life = 200;
},
update: function(emitter, particle, index) {
particle.velocity.x += Math.random() - 0.5;
particle.velocity.y += Math.random() - 0.5;
}
});


As you can see, after creating the emitter itself, we are adding two properties to it: A counter and a behaviour.


Counters regulate the emission rate and instruct the emitter, how many new particles it has to create at any given time. In our example, we create 1 new particle every frame and no extra particles, when the emitter starts. Each emitter can only have 1 counter and defaults to a dummy instance, that causes no particles to be created.


 


Behaviours control, how particles are created and updated, how the look and interact with each other and their surroundings. They are powerful, but can get very complex. In our example, we assign a texture to the particle and set its starting position to the center of the screen. During each update, it will accelerate in a random direction and increase its age counter by 1, before finally dying after 200 updates. Each emitter can have any number of behaviours assigned and they are executed in the order they were added.


 


Now, the only thing left to do is to start the emitter and add it to the scene. The Emitter class contains a number of functions to interact with emitters and each of them returns the emitter itself, so they can be chained:



emitter.start(); Starts the emitter. Before calling this function, it will simply do nothing.
emitter.stop(); Stops the emitter, causing all particle creation and updating to stop.
emitter.resume(); Resumes the emitter, after it has previously been stopped.
emitter.skip(count); Fast forwards a number of update cycles. Creates and updates particles accordingly.
emitter.clear(); Removes all current particles from the emitter.
emitter.setCounter(counter); Sets the counter to be used. Needs to implement "start" and "update" functions.
emitter.setFactory(factory); Replaces the default particle factory. Needs to implement "create" and "dispose".
emitter.addBehaviour(...b); Adds one or more behaviours to the emitter.
emitter.removeBehaviour(b); Removes all occurences of a given behaviour from the emitter.
emitter.removeAllBehaviours(); Removes all behaviours from the emitter.


Adding or removing behaviours while the emitter is running, affects both new and existing particles, so keep that in mind. Inside a behaviour, the following properties of the particle can be accessed:

Code:
texture        (PIXI.Texture)    Image to be displayed for the particle. If this is not set, you won't see anything.
life           (number)          The particle's lifespan. Defaults to Infinity.
age            (number)          Read-only. Starts at 0 and can be used to track the particle's age.
dead           (boolean)         If this gets set to true, the particle will be disposed by the emitter.
oldPosition    (PIXI.Point)      Read-only. Gets set to the particle's position before the last update.
position       (PIXI.Point)      The particle's current position. Automatically gets updated every update.
velocity       (PIXI.Point)      Marks the rate, at which the particle's position changes.
scale          (PIXI.Point)      Scaling factor of the particle. Its x and y value should be kept synchron.
radius         (number)          Gets used by some behaviours to implement collision.
alpha          (number)          Handles the particle's transparency on a scale from 0 (transparent) to 1 (opaque).
rotation       (number)          The particle's rotation around its center point, in radians.
tint           (number)          Tinting color of the particle, as hex number. 0xFFFFFF removes all tinting.
blendMode      (number)          Blend mode to be used. Support variies between renderers. Default is 0.



Terms of Use


Free to use for both commercial and non-commercial games. Please give credit.


Download


http://pastebin.com/ss7T05b0


Changelog


v1.00 - First version of the engine.


v1.01 - Revamped the engine structure by (re)introducing behaviours.


v1.02 - Moved particle aging from behaviours into the emitter.


v1.03 - Introducing activities, which run during each update, but before particles are updated.


v1.04 - Added a way for behaviours to store and read data on a particle.

Latest Threads

Latest Profile Posts

Day 9 of giveaways! 8 prizes today :D
He mad, but he cute :kaopride:

Our latest feature is an interview with... me?!

People4_2 (Capelet off and on) added!

Just beat the last of us 2 last night and starting jedi: fallen order right now, both use unreal engine & when I say i knew 80% of jedi's buttons right away because they were the same buttons as TLOU2 its ridiculous, even the same narrow hallway crawl and barely-made-it jump they do. Unreal Engine is just big budget RPG Maker the way they make games nearly identical at its core lol.

Forum statistics

Threads
106,037
Messages
1,018,464
Members
137,821
Latest member
Capterson
Top