Class: phaserJuice

phaserJuice(scene)

GitHub: https://github.com/retroVX/phaser3Juice
Create juice effects with Phaser 3

Constructor

new phaserJuice(scene)

Parameters:
Name Type Description
scene Phaser.Scene The Scene the phaserJuice will be created in (this)
Author:
  • Conor Irwin <https://github.com/RetroVX>
License:
Source:
Example
this.juice = new phaserJuice(this);
this.juice.shake(target);

Members

(static) options :function

Tween options that can be overidden depending on effect settings.
Every tweenable effect has access to the delay, paused, onStart and onComplete parameters. Depending on which parameters the effect uses, you can edit each effect using the optional config parameter inside each effect.
For example. To edit the shake effect to shake left and right instead of up and down
.shake(sprite, { x: 5, y: 0 })
Type:
  • function
Since:
  • 1.0.0
Source:

(static) scene :Object

Get 'this' from scene
Type:
  • Object
Since:
  • 1.0.0
Source:

Methods

(static) add(target) → {function|function}

Parameters:
Name Type Description
target object sprite to chain
Since:
  • 1.1.0
Source:
Returns:
  • Type
    function
  • for method chaining
    Type
    function

(static) bounce(target, configopt, destroyopt) → {function|function}

Bounce a sprite
The bounce default config and options to overide if using the config parameter
const bounceConfig = { y: 25, duration: 1000, ease: 'Bounce', delay: 0, paused: false, }
Parameters:
Name Type Attributes Default Description
target object sprite to bounce
config object <optional>
config to make edits to the effect
destroy boolean <optional>
false destroy the tween when the onComplete event fires
Since:
  • 1.0.0
Source:
Returns:
  • Type
    function
  • for method chaining
    Type
    function

(static) fadeIn(target, configopt, destroyopt) → {function|function}

Fade in a sprite
The fade in default config and options to overide if using the config parameter
const fadeInConfig = { alpha: 1, duration: 750, ease: 'Circular.easeIn', delay: 0, paused: false, }
Parameters:
Name Type Attributes Default Description
target object sprite to fade in
config object <optional>
config to make edits to the effect
destroy boolean <optional>
false destroy the tween when the onComplete event fires
Since:
  • 1.0.0
Source:
Returns:
  • Type
    function
  • for method chaining
    Type
    function

(static) fadeInOut(target, configopt, destroyopt) → {function|function}

Fade in and out a sprite
The fade in & out default config and options to overide if using the config parameter
const fadeInOutConfig = { alpha: 0, duration: 500, yoyo: true, repeat: 3, ease: 'Circular.easeInOut', delay: 0, paused: false, }
Parameters:
Name Type Attributes Default Description
target object sprite to fade in and out
config object <optional>
config to make edits to the effect
destroy boolean <optional>
false destroy the tween when the onComplete event fires
Since:
  • 1.0.0
Source:
Returns:
  • Type
    function
  • for method chaining
    Type
    function

(static) fadeOut(target, configopt, destroyopt) → {function|function}

Fade out a sprite
The fade out default config and options to overide if using the config parameter
const fadeOutConfig = { alpha: 0, duration: 750, ease: 'Circular.easeOut', delay: 0, paused: false, }
Parameters:
Name Type Attributes Default Description
target object sprite to fade out
config object <optional>
config to make edits to the effect
destroy boolean <optional>
false destroy the tween when the onComplete event fires
Since:
  • 1.0.0
Source:
Returns:
  • Type
    function
  • for method chaining
    Type
    function

(static) flash(target, durationopt, coloropt) → {function|function}

Flash a sprite
Note: Flash does not use a tween
Parameters:
Name Type Attributes Default Description
target object sprite to flash
duration number <optional>
150 how long the effect lasts for.
color string <optional>
'0xffffff' The color the sprite flashes.
Since:
  • 1.0.0
Source:
Returns:
  • Type
    function
  • for method chaining
    Type
    function

(static) flipX(target, directionopt, configopt, destroyopt) → {function|function}

Flip a sprite on the x-axis
The flipX default config and options to overide if using the config parameter
Warning: This effect scales the sprite and can cause unintended side effects!
const flipXConfig = { scaleX: direction, duration: 500, ease: 'Sine.easeInOut', delay: 0, paused: false, }
Parameters:
Name Type Attributes Default Description
target object sprite to flip
direction boolean <optional>
true direction to flip the tween. True to flip, false to flip back
config object <optional>
config to make edits to the effect
destroy boolean <optional>
false destroy the tween when the onComplete event fires
Since:
  • 1.0.0
Source:
Returns:
  • Type
    function
  • for method chaining
    Type
    function

(static) flipY(target, directionopt, configopt, destroyopt) → {function|function}

Flip a sprite on the y-axis
The flipY default config and options to overide if using the config parameter
Warning: This effect scales the sprite and can cause unintended side effects!
const flipYConfig = { scaleY: direction, duration: 500, ease: 'Sine.easeInOut', delay: 0, paused: false, }
Parameters:
Name Type Attributes Default Description
target object sprite to flip
direction boolean <optional>
true direction to flip the tween. True to flip, false to flip back
config object <optional>
config to make edits to the effect
destroy boolean <optional>
false destroy the tween when the onComplete event fires
Since:
  • 1.0.0
Source:
Returns:
  • Type
    function
  • for method chaining
    Type
    function

(static) pulse(target, configopt, destroyopt) → {function|function}

Pulse a sprite
The pulse default config and options to overide if using the config parameter
const pulseConfig = { scaleX: target.scaleX * 1.25, scaleY: target.scaleY * 1.25, duration: 750, repeat: 2, yoyo: true, ease: 'Quad.easeInOut', delay: 0, paused: false, }
Parameters:
Name Type Attributes Default Description
target object sprite to pulse
config object <optional>
config to make edits to the effect
destroy boolean <optional>
false destroy the tween when the onComplete event fires
Since:
  • 1.0.0
Source:
Returns:
  • Type
    function
  • for method chaining
    Type
    function

(static) reset(target) → {function|function}

Helper function to reset a sprite back to original
Resets the sprite to alpha 1, scale 1, angle 0, tint none
Parameters:
Name Type Description
target object sprite to reset
Since:
  • 1.0.0
Source:
Returns:
  • Type
    function
  • for method chaining
    Type
    function

(static) rotate(target, configopt, destroyopt) → {function|function}

Rotate a sprite
The rotate default config and options to overide if using the config parameter
const rotateConfig = { angle: 360, duration: 500, ease: 'Circular.easeInOut', delay: 0, paused: false, }
Parameters:
Name Type Attributes Default Description
target object sprite to rotate
config object <optional>
config to make edits to the effect
destroy boolean <optional>
false destroy the tween when the onComplete event fires
Since:
  • 1.0.0
Source:
Returns:
  • Type
    function
  • for method chaining
    Type
    function

(static) scaleDown(target, configopt, destroyopt) → {function|function}

Scale down a sprite
The scaleDown default config and options to overide if using the config parameter
const shrinkConfig = { scaleX: target.scaleX - 0.25, scaleY: target.scaleY - 0.25, duration: 750, delay: 0, paused: false, }
Parameters:
Name Type Attributes Default Description
target object sprite to shrink
config object <optional>
config to make edits to the effect
destroy boolean <optional>
false destroy the tween when the onComplete event fires
Since:
  • 1.0.0
Source:
Returns:
  • Type
    function
  • for method chaining
    Type
    function

(static) scaleUp(target, configopt, destroyopt) → {function|function}

Scale up a sprite
The scaleUp default config and options to overide if using the config parameter
const growConfig = { scaleX: target.scaleX + 0.25, scaleY: target.scaleY + 0.25, duration: 750, delay: 0, paused: false, }
Parameters:
Name Type Attributes Default Description
target object sprite to grow
config object <optional>
config to make edits to the effect
destroy boolean <optional>
false destroy the tween when the onComplete event fires
Since:
  • 1.0.0
Source:
Returns:
  • Type
    function
  • for method chaining
    Type
    function

(static) shake(target, configopt, destroyopt) → {function|function}

Shake a sprite
The shake default config and options to overide if using the config parameter
const shakeConfig = { x: 5, y: 0, duration: 50, yoyo: true, repeat: 8, ease: 'Bounce.easeInOut', delay: 0, paused: false, }
Parameters:
Name Type Attributes Default Description
target object sprite to shake
config object <optional>
config to make edits to the effect
destroy boolean <optional>
false destroy the tween when the onComplete event fires
Since:
  • 1.0.0
Source:
Returns:
  • Type
    function
  • for method chaining
    Type
    function

(static) shakeY(target) → {function|function}

Helper alternative that shakes the sprite on y axis instead of x
Parameters:
Name Type Description
target object sprite to shake
Since:
  • 1.0.0
Source:
Returns:
  • Type
    function
  • for method chaining
    Type
    function

(static) spinX(target, directionopt, configopt, destroyopt) → {function|function}

Spin a sprite on the x-axis
The spinX default config and options to overide if using the config parameter
Warning: This effect scales the sprite and can cause unintended side effects!
const spinXConfig = { scaleX: direction, duration: 500, yoyo: true, repeat: 3, ease: 'Sine.easeInOut', delay: 0, paused: false, }
Parameters:
Name Type Attributes Default Description
target object sprite to spin
direction boolean <optional>
true direction to spin the tween. True to spin right, false to spin back
config object <optional>
config to make edits to the effect
destroy boolean <optional>
false destroy the tween when the onComplete event fires
Since:
  • 1.0.0
Source:
Returns:
  • Type
    function
  • for method chaining
    Type
    function

(static) spinY(target, directionopt, configopt, destroyopt) → {function|function}

Spin a sprite on the y-axis The spinY default config and options to overide if using the config parameter
Warning: This effect scales the sprite and can cause unintended side effects!
const spinYConfig = { scaleY: direction, duration: 500, yoyo: true, repeat: 3, ease: 'Sine.easeInOut', delay: 0, paused: false, }
Parameters:
Name Type Attributes Default Description
target object sprite to spin
direction boolean <optional>
true direction to spin the tween. True to spin right, false to spin back
config object <optional>
config to make edits to the effect
destroy boolean <optional>
false destroy the tween when the onComplete event fires
Since:
  • 1.0.0
Source:
Returns:
  • Type
    function
  • for method chaining
    Type
    function

(static) wobble(target, configopt, destroyopt) → {function|function}

Add a slight wobble to a sprite
The wobble default config and options to overide if using the config parameter
const wobbleConfig = { x: 20, y: 0, duration: 150, yoyo: true, repeat: 5, ease: 'Sine.easeInOut', delay: 0, paused: false, }
Parameters:
Name Type Attributes Default Description
target object sprite to wobble
config object <optional>
config to make edits to the effect
destroy boolean <optional>
false destroy the tween when the onComplete event fires
Since:
  • 1.0.0
Source:
Returns:
  • Type
    function
  • for method chaining
    Type
    function

(static) wobbleY(target) → {function|function}

Helper alternative that wobbles the sprite on y axis instead of x
Parameters:
Name Type Description
target object sprite to wobble
Since:
  • 1.0.0
Source:
Returns:
  • Type
    function
  • for method chaining
    Type
    function