Home Reference Source

src/behaviour/Gravity.js

  1. import Force from './Force';
  2. import { getEasingByName } from '../ease';
  3. import { BEHAVIOUR_TYPE_GRAVITY as type } from './types';
  4.  
  5. /**
  6. * Behaviour that forces particles down the y axis.
  7. *
  8. */
  9. export default class Gravity extends Force {
  10. /**
  11. * Constructs a Gravity behaviour instance.
  12. *
  13. * @param {number} gravity - the force to pull the particle down the y axis
  14. * @param {number} life - the life of the particle
  15. * @param {string} easing - the easing equation to use
  16. * @param {boolean} [isEnabled=true] - Determines if the behaviour will be applied or not
  17. * @return void
  18. */
  19. constructor(gravity, life, easing, isEnabled = true) {
  20. super(0, -gravity, 0, life, easing, isEnabled);
  21.  
  22. /**
  23. * @desc The class type.
  24. * @type {string}
  25. */
  26. this.type = type;
  27. }
  28.  
  29. static fromJSON(json) {
  30. const { gravity, life, easing, isEnabled = true } = json;
  31.  
  32. return new Gravity(gravity, life, getEasingByName(easing), isEnabled);
  33. }
  34. }