Run this command to install devkit-effects as a dependency in your project:
devkit install https://github.com/gameclosure/devkit-effects.git
Once installed, you can import effects like this:
import effects;
All effects take two parameters: a view and an optional opts object. Effects also looks for a view property so you can pass in something like an Entity
.
Call effects like this:
effects.explode(view);
or:
effects.disco(player, { duration: 4000 });
The following functions can be called on effects to help manage active effects:
effects.pause()
- optional parametersview
and effectname
- pauses all effects globally, all effects on a given view, or a specific effect on a specific vieweffects.resume()
- optional parametersview
and effectname
- resumes all effects globally, all effects on a given view, or a specific effect on a specific vieweffects.stop()
- optional parametersview
and effectname
- clears all effects globally, all effects on a given view, or a specific effect on a specific vieweffects.commit()
- optional parametersview
and effectname
- instantly and safely finishes all effects globally, all effects on a given view, or a specific effect on a specific view
For example, pause all effects, but resume only one of them:
effects.pause();
effects.resume(player, 'disco');
These properties can be passed in to modify effects:
duration
- number in milliseconds - change the time an effect takes to complete, defaults to 1000 for most effects (1 second)scale
- number - change the general scale or magnitude of an effect, defaults to 1 for most effectsloop
- boolean - whether or not to continually repeat an effect, defaults to false for most effectsblend
- boolean - whether or not to blend an effect using composite operations, defaults to false for most effects, only affects particlesfollow
- boolean - whether particles should follow a view as it moves, defaults to false for most effects, only affects particles,follow: false
can create particle trails, try it with theconfetti
effect!behind
- boolean - whether particles should be in front or behind the view, defaults to false for most effects, only affects particles
hover
- hover a view up and downshake
- shake a view rapidly, great for screen shaking like earthquakesspin
- rotate a viewsquish
- make a view squish like jellysway
- sway a view back and forth
confetti
- basic confetti effect, has default imagesexplode
- basic fiery explosion, has default imagesfirework
- an explosion that looks like a firework, has default imagessparkle
- basic sparkly effect, has default images
disco
- disco-mode, has default imagesradial
- awe-inspiring radials, has default images
Although this is possible using exposed API's, it's recommended to avoid until better tested and documented! Read the code in effects.js
if you're super curious!
registerAnimationEffect
- uses timestep'sanimate
to create animation effects, like bounces or shakesregisterParticleEffect
- uses timestep'sParticleEngine
to create particle effects, like sparkles or explosionsregisterCompositeEffect
- uses timestep'sBlendEngine
to create composited particle effects, like disco-mode