Iavra Particle Engine

Iavra

Veteran
Veteran
Joined
Apr 9, 2015
Messages
1,797
Reaction score
857
First Language
German
Primarily Uses
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.
 
Last edited by a moderator:

Iavra

Veteran
Veteran
Joined
Apr 9, 2015
Messages
1,797
Reaction score
857
First Language
German
Primarily Uses
Plugin


Particle Engine - Counters


Description


Extension, that comes with an assortment of counters to be used for the particle engine.


Author


Iavra


How to Use


When setting an emitter's counter, you can specify one of the classes contained in this plugin, like this:


emitter.setCounter(new IAVRA.PARTICLE.C.Blast(10));


The example creates a Blast counter, which will create a certain number of particles, when the emitter starts and no particles during runtime.



The following counters are contained in the IAVRA.PARTICLE.C / IAVRA.PARTICLE.COUNTER namespace:


Blast(count)
Creates a number of particles, when the emitter starts and none during runtime. Can be overloaded, by supplying an array instead, which contains the range used to calculate a random number of particles.

Trigger(count)
Creates a number of particles, whenever its "trigger" function is called. Can be overloaded, by supplying an array instead, which contains the range used to calculate a random number of particles.

Interval(count, interval)
Creates the given number of particles in a given interval, in frames. Both parameters can be overloaded by supplying an array, instead, which contains the range used to generate random numbers.

Variable(countVar, intervalVar)
Creates a number of particles at a variable rate, both of which are defined by the given variables.

Switch(counter, switchId)
Wraps another counter object and surpresses it, if the given switch is set to OFF.




Terms of Use


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


Download


http://pastebin.com/Ti4L62Gu


Changelog


v1.00 - First version of the plugin.


v1.01 - The "Steady" counter has been renamed to "Interval" and now also allows randomization.
 
Last edited by a moderator:

Iavra

Veteran
Veteran
Joined
Apr 9, 2015
Messages
1,797
Reaction score
857
First Language
German
Primarily Uses
Plugin


Particle Engine - Behaviours


Description


Extension, that comes with predefined behaviours to be used with the particle engine.


How to Use


To use one of the behaviours included in this plugin, provide it as an argument to the "addBehaviour" function of your created emitter:


emitter.addBehaviour(new IAVRA.PARTICLE.B.Life(200));


This example will register a "Life" behaviour, that will cause particles to die after 200 frames.

The following counters are contained in the IAVRA.PARTICLE.B / IAVRA.PARTICLE.BEHAVIOUR namespace:


BindToMap(offset)
Moves the emitter and all of its particles with the map.

BindToPlayer(offset)
Moves the emitter and all of its particles with the player.

BindToEvent(id, offset)
Moves the emitter and all of its particles with the given event.

Position(zone)
Sets the starting position of created particles to a random point inside the given zone.

Radius(radius)
Sets the collision radius of created particles to the given value. Behaviours using this property need to make sure to factor in the particle's scale as well.

Image(image, scaling)
Sets the texture to be displayed by created particles. Can be overloaded by specifying multiple images and will pick one of them at random.

Velocity(x, y)
Increases the starting velocity of created particles by the given amount. Can be overloaded to randomize the actual values.

PolarVelocity(radius, angle)
Increases the starting velocity of created particles by a vector calculated from the given radius and angle. Can be overloaded to randomize the actual values.

Blend(mode)
Sets the blend mode of created particles. PIXI.blendModes features a full list of all available modes. Support variies between renderers.

Life(life, easing)
Sets the particle's life to the given value. Can be overloaded to randomize the actual values. Also, will set the particle's energy according to its life and age.

Scale(startScale, endScale)
Transitions the particle's scale between the given start and end values.

Alpha(startAlpha, endAlpha)
Transitions the particle's alpha value between the given start and end values.

Rotation(startAngle, endAngle)
Transitions the particle's rotation between the given start and end values.

Color(startColor, endColor)
Transitions the particle's tinting color between the given start and end values.

Friction(friction)
Applies linear friction to particles, causing them to slow down over time.

Force(x, y)
Applies a linear force to particles.

PolarForce(radius, angle)
Applies a linear force to particles, that gets calculated from a polar vector.

RandomDrift(x, y)
Randomly accelerates particles.

SpeedLimit(min, max)
Limits the velocity of particles to a given range.

Attraction(center, force, epsilon)
Places a gravity well at a given point, that will attract particles depending on their distance.

Repulsion(center, force, epsilon)
Places an anti-gravity well at a given point, that will repel particles depending on their distance.

RotateToDirection()
Rotates particles to always face in the direction, they are moving to.

Collision(bounce)
Applies collision between all particles of the emitter, depending on their radius and scale.

BoundingBox(x, y, width, height, bounce)
Restricts particles to a bounding box, causing them to bounce back, if they try to leave it. Particles should spawn inside the box, to prevent unpredictable side effects.

WrapAroundBox(x, y, width, height)
Restricts particles to a bounding box, causing them to wrap around to the other side, if they try to leave it. Particles should spawn inside the box, to prevent unpredictable side effects.

CollisionZone(zone, bounce)
Applies collision between particles and the given zone, both from the inside and outside.

DeathZone(zone, killOutside)
Destroys all particles in- or outside the given zone.




Terms of Use


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


Download


http://pastebin.com/4AKdZhch


Changelog


v1.00 - First version of the plugin.
 
Last edited by a moderator:

Iavra

Veteran
Veteran
Joined
Apr 9, 2015
Messages
1,797
Reaction score
857
First Language
German
Primarily Uses
Plugin


Particle Engine - Zones


Description


Extension, that comes with predefined zones for use by some behaviours.


How to Use


To use one of the zones included in this plugin, provide it as an argument to behaviours requiring a zone argument:


new IAVRA.PARTICLE.B.Position(new IAVRA.PARTICLE.Z.Point(100, 100));


This example will create a "Position" behaviour with a "Point" zone, that will cause particles to spawn at the point (100, 100).


The following zones are contained in the IAVRA.PARTICLE.Z / IAVRA.PARTICLE.ZONE namespace:


Multi(...zone)
Can be used to merge multiple zones, which are weighted depending on their area.

Point(x, y)
Defines a single point at the position (x, y).

Line(x1, y1, x2, y2)
Creates a line from the start point (x1, y1) to the end point (x2, y2).

Circle(center, outerRadius, innerRadius)
Creates a center around the given center point with the given radius. The "innerRadius" parameter can be used to turn the circle into a ring.

Rect(x, y, width, height)
Defines a rectangle parallel to the axes with the given upper left edge (x, y), as well as the given width an height.

Image(imageData, x, y, skip)
Creates a zone, that contains all non-transparent pixels from the given image data, offset by the given x and y values, The parameter skip can be used to skip pixels, which speeds up the creation of this zone.


Regarding the Image zone, there are multiple ways to aquire an image data object. The following describes how to do it using PIXI.RenderTexture:


var sprite = PIXI.Sprite.fromImage('img/imageToBeUsed.png'); // Make sure, that this is loaded, before continuing.
var render = new PIXI.RenderTexture(sprite.width, sprite.height);
var imageData = render.getCanvas.getContext('2d').getImageData(0, 0, render.width, render.height);




Terms of Use


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


Download


http://pastebin.com/ziHGy2pR


Changelog


v1.00 - First version of the plugin.
 
Last edited by a moderator:

KaYsEr

Koruldia
Veteran
Joined
Mar 14, 2014
Messages
220
Reaction score
449
First Language
French
Primarily Uses
RMMV
A particle engine in MV!!!!!


:o


OK it's like Christmas one month later now! I'll give it a try, thank you!
 

Iavra

Veteran
Veteran
Joined
Apr 9, 2015
Messages
1,797
Reaction score
857
First Language
German
Primarily Uses
The engine has been modified to better fit with predefined behaviours (to be done). I also added the Counters addon, which allows you to use predefined counters to regulate the emission rate.
 

fizzly

Veteran
Veteran
Joined
Mar 23, 2012
Messages
458
Reaction score
311
First Language
Polish
Primarily Uses
RMMV
Can't wait to test it out!!
 

Iavra

Veteran
Veteran
Joined
Apr 9, 2015
Messages
1,797
Reaction score
857
First Language
German
Primarily Uses
The core plugin has been updated to v1.02. I decided to handle aging inside the emitter (since it felt like too much of a hassle, when not using predefined behaviours...those are coming soon, btw). This means, that "particle.age" is now read-only and you don't have to manually increase it or mark the particle as dead (you still can, though, if you want to prematurely kill a particle).


/edit:


The core plugin has been updated to v1.03. Behaviours can now implement a third method, besides "setup" and "update": activity. The name is inspired by the Flint behaviour and works similar. Following is a single update cycle of an emitter:


- ask the counter, how many new particles to create


- create particles


- call activities


- update particles


- dispose dead particles


As you can see, activities are executed, before particles are updated, so they can be used to either update the emitter (for example, to make sure it moves with the map or a specific event) or to store information inside the behaviour, that are independent from individual particles.
 
Last edited by a moderator:

Liandra Aura

Game Director
Veteran
Joined
Feb 21, 2013
Messages
128
Reaction score
63
First Language
English
Primarily Uses
RMMV
Is there any chance that we could get a demo on here for this showing off all of the various options. I always loved particle engines for RPG Makers. Good to see that it's in development.


Keep up the great work and I can't wait to see this finished.
 

Iavra

Veteran
Veteran
Joined
Apr 9, 2015
Messages
1,797
Reaction score
857
First Language
German
Primarily Uses
I'm a lazy person, so i can't promise anything, but i will try to get a short video together after finishing the missing 2 plugins (behaviours and zones). It might now show everything (there are currently 27 behaviours and 5-6 zones, so there are a lot of combinations possible), though.


/edit: v1.00 of the behaviour extension has been released. Note, that some behaviours rely on zones, so you'll need to create your own zone classes for now, until the zone extension gets released.
 
Last edited by a moderator:

fizzly

Veteran
Veteran
Joined
Mar 23, 2012
Messages
458
Reaction score
311
First Language
Polish
Primarily Uses
RMMV
Yeah, tried to test it but can't get it to work so I'll be happy for demo too.
 

Iavra

Veteran
Veteran
Joined
Apr 9, 2015
Messages
1,797
Reaction score
857
First Language
German
Primarily Uses
Version 1.00 of the zone plugin has been released, so the engine is now complete to be used. Planned features for the future include:


- Either a demo or video to showcase the possibilities.


- Add a "dictionary" of sorts to the particles, that can be used to store information in them (also needs a way to uniquely identify behaviours).


- With the dictionary: Add an option to randomize certain behaviours, like "Scale" on a per-particle basis.


- Add a new behaviour, that acts as a wrapper and delays/limits/loops wrapped behaviours to create more complex sequences.


@fizzly: You can create a sample emitter in the console (F8) like this:

Code:
var emitter = new IAVRA.PARTICLE.Emitter()
	.setCounter(new IAVRA.PARTICLE.C.Blast(100))
	.addBehaviour(
		new IAVRA.PARTICLE.B.Image('img/particle.png'), 
		new IAVRA.PARTICLE.B.Position(new IAVRA.PARTICLE.Z.Point(Graphics.width / 2, Graphics.height / 2)), 
		new IAVRA.PARTICLE.B.PolarVelocity(3, [0, 360]), 
		new IAVRA.PARTICLE.B.BoundingBox(0, 0, Graphics.width, Graphics.height)
	).start(); 

SceneManager._scene.addChild(emitter);
 
Last edited by a moderator:

takashi1kun

spaghetti god code
Veteran
Joined
Jul 27, 2014
Messages
104
Reaction score
38
First Language
Spain Spanish
Primarily Uses
Version 1.00 of the zone plugin has been released, so the engine is now complete to be used. Planned features for the future include:


- Either a demo or video to showcase the possibilities.


- Add a "dictionary" of sorts to the particles, that can be used to store information in them (also needs a way to uniquely identify behaviours).


- With the dictionary: Add an option to randomize certain behaviours, like "Scale" on a per-particle basis.


- Add a new behaviour, that acts as a wrapper and delays/limits/loops wrapped behaviours to create more complex sequences.


@fizzly: You can create a sample emitter in the console (F8) like this:



var emitter = new IAVRA.PARTICLE.Emitter()
.setCounter(new IAVRA.PARTICLE.C.Blast(100))
.addBehaviour(
new IAVRA.PARTICLE.B.Image('img/particle.png'),
new IAVRA.PARTICLE.B.Position(new IAVRA.PARTICLE.Z.Point(Graphics.width / 2, Graphics.height / 2)),
new IAVRA.PARTICLE.B.PolarVelocity(3, [0, 360]),
new IAVRA.PARTICLE.B.BoundingBox(0, 0, Graphics.width, Graphics.height)
).start();

SceneManager._scene.addChild(emitter);
its possible to atach it to a bitmap and not to a scene? its because i want it to be under certain pictures but over other pictures, the pictures that you call whit a event of rpg maker, exactly im making a custom title, i want it to be over the bg, but not over the letters of the title or the buttons of the menu(aslo pictures) how i can archive it? 
 

Iavra

Veteran
Veteran
Joined
Apr 9, 2015
Messages
1,797
Reaction score
857
First Language
German
Primarily Uses
An emitter can be added to any element, that extends PIXI.DisplayObjectContainer, including sprites. I probably won't write extensive tutorials on how to use this, since the plugin is very much intended for experienced scripters.
 
Last edited by a moderator:

Anisoft

Great Desu King
Veteran
Joined
Jun 17, 2015
Messages
94
Reaction score
74
First Language
English
Primarily Uses
Wow this is a really interesting engine. It seems very powerful in what it can do. 

Few questions if you don't mind me asking.


1) How would you go about triggering this via an Event? I'm currently in the works of writing my own particle and if this engine can already be triggered via an event this saves me a lot of time. An example would be lighting a fireplace, and after switching a switch, the emitter can trigger.

2) The engine I was attempting to write would also be able to save particles before going to menu, thus letting them spawn back the same way they were before when reloading the map. Can this engine save particles and reload them in a similar manner. (This would also allow menu transitions to save the current location of a particle as well.) 


4) Can I control the depths of the particles as well, so I can spawn them behind or in front of a character based on current location on the map, and or just layer two emitters (one back, and one front) 


3) Does this engines "zones" mean something along the lines of vector paths or areas which change the direction or speed of a particle. This is so I can create wind or locations that effect the particles overall to apply more dynamic change ups and motion.  

If this engine doesn't already I would at least like to know if you have an idea for triggering an emitter through an event, to at least help my script, and or future implementation of yours. 

Thanks for taking the time to read this. And really great work so far!
 

Iavra

Veteran
Veteran
Joined
Apr 9, 2015
Messages
1,797
Reaction score
857
First Language
German
Primarily Uses
I am currently rewriting the engine (in my sparetime, which isn't much), but i'll try to remember as much as possible about this version ^^


1) You can prepare the emitter and add it to the scene in code. It won't do anything, before its start() function is called, which is what your event can do.


2) You can store a reference somewhere, before exiting the map scene and readd it again when leaving the menu. It won't update in the meantime, because its update() function isn't called. However, i don't think that particles can currently be stored in the savegame, so the animation would start from the beginning.


3) (you kinda mixed up the order :D) "Zones" in this case are shapes like rectangles or circles, that can be used to contain particles and limit the space they are allowed to move. Though you could use a line zone and use it like a vector.


4) You would need 2 emitters to do so.


The engine currently has some weird behaviours because of the fact, that the emitter serves as a container for the particles. If you rotate or move the emitter, this means also moving every particle it created, which feels odd when coming from different engines (also, if the emitter dies, all of its particles do so as well). The new engine version will add particles to the emitter's parent, instead, so they are completely independent from each other.


Furthermore, there is no "Emitter" class anymore, but an "Emit" behaviour, that can be added to particles, effectively turning them into emitters. This will make it easier to create emitters producing emitters on their own for more complex effects.


It probably still won't be possible to save the emitter state to a savegame, since particles are part of the scene, which is not saved in general, and might cause all sorts of issues.
 

Anisoft

Great Desu King
Veteran
Joined
Jun 17, 2015
Messages
94
Reaction score
74
First Language
English
Primarily Uses
Thanks for taking the time to respond! How exact;y would you go about triggering your engine in an event via code? Is it just a script call to the particle engine? 


Seeing that this doesn't support temporarily saving and then reloading the particles in a scene, I'm just going to go through with finishing my own. The problem I'm facing is triggering it via an event.
 

Iavra

Veteran
Veteran
Joined
Apr 9, 2015
Messages
1,797
Reaction score
857
First Language
German
Primarily Uses
Assuming you have created the emitter as stated in the OP and added it to the scene, you only have to execute the following scriptcall in your event:


emitter.start();


I would suggest keeping a reference to the emitter somewhere, so it won't get destroyed when leaving the scene. This way, you can readd it to the scene when, say, exiting the menu and have the animation proceed, instead of restarting everytime.
 

Anisoft

Great Desu King
Veteran
Joined
Jun 17, 2015
Messages
94
Reaction score
74
First Language
English
Primarily Uses
^Referencing it and using it again was exactly what I meant when I said "save" if this can really do that, then I probably don't have to write my own after all! 
 

Iavra

Veteran
Veteran
Joined
Apr 9, 2015
Messages
1,797
Reaction score
857
First Language
German
Primarily Uses
Ah, no, what i meant was actually storing the emitter's state in a savegame, so it will continue after loading the game.
 

Users Who Are Viewing This Thread (Users: 0, Guests: 1)

Latest Threads

Latest Profile Posts

fighting game fans might really enjoy my game battle wise, and I feel non fighting fans might learn some stuff. thanks row system. pokes, neutral, and zoning time...
This community is awesome. They helped me get my eventing processes to work. I love you all.
suspended on twitter for calling an ahole an ahole & appealing the tweet; furious at myself for being even slightly upset with my suspension: oh no, you've been temporarily banned from hell. GET OVER IT, me.
how can you download the tiles from a forum post here? HELP
That moment when you post the wrong download link to your game and wonder why it got so few downloads... :mad:

Forum statistics

Threads
94,247
Messages
919,381
Members
123,960
Latest member
crayonchan
Top