Sunday, May 28, 2017

Particles

For complex effects in graphics engines, using standard drawable types like image files can lead to memory and cpu-intensive operations, and the general solution for this is to use a Particle engine. Particle engines are named as such because their core renderable object, the Particle, is lightweight to draw to screen and update.

In Oak, we have four groups of particles:

  • Color particles, which can be assigned a start color and end color for however long they last, smoothly transitioning from one to the other.
  • Gradient particles, which are just like color particles but can have their particle be a circular or horizontal gradient, or something similar.
  • Sprite particles, which throw away 'being lightweight' and just serve as generators for sprite images or other renderable types in the engine like animations. 
  • Collision particles, which wrap around any other particle but contain a collision space so they can react to the game environment. 
Oak's particle engine is based off of CraftyJS's particle engine, with significant modifications (and written from scratch, as we're in a different language). Some settings a particle can have are how gravity affects them, how much they rotate per frame, how fast they move, what angle they move at, and so on. Below is a demo of how most of these effects change a single color particle source:


The code used to make this demo (which is an oak program) can be seen here, (although it needs some documentation!)

No comments:

Post a Comment