Skip to content

Ease-move

Introduction

Ease-move game object.

  • Author: Rex
  • Method only

Usage

Sample code

Install plugin

Load minify file

  • Load plugin (minify file) in preload stage
    scene.load.plugin('rexeasemoveplugin', 'https://raw.githubusercontent.com/rexrainbow/phaser3-rex-notes/master/dist/rexeasemoveplugin.min.js', true);
    
  • Ease-move to/from
    var easemove = scene.plugins.get('rexeasemoveplugin').moveTo(gameObject, duration, x, y, ease);
    var easemove = scene.plugins.get('rexeasemoveplugin').moveFrom(gameObject, duration, x, y, ease);
    

Import plugin

  • Install rex plugins from npm
    npm i phaser3-rex-plugins
    
  • Install plugin in configuration of game
    import EaseMovePlugin from 'phaser3-rex-plugins/plugins/easemove-plugin.js';
    var config = {
        // ...
        plugins: {
            global: [{
                key: 'rexEaseMove',
                plugin: EaseMovePlugin,
                start: true
            },
            // ...
            ]
        }
        // ...
    };
    var game = new Phaser.Game(config);
    
  • Ease-move to/from
    var easemove = scene.plugins.get('rexEaseMove').moveTo(gameObject, duration, x, y, ease);
    var easemove = scene.plugins.get('rexEaseMove').moveFrom(gameObject, duration, x, y, ease);
    

Import method

  • Install rex plugins from npm
    npm i phaser3-rex-plugins
    
  • Import method
    import { EaseMoveTo, EaseMoveFrom } from 'phaser3-rex-plugins/plugins/easemove.js';
    
  • EaseMove-out-destroy
    var easemove = EaseMoveTo(gameObject, duration, x, y, ease);
    var easemove = EaseMoveFrom(gameObject, duration, x, y, ease);
    

Move to

var easemove = scene.plugins.get('rexEaseMove').moveTo(gameObject, duration, x, y);
// var easemove = scene.plugins.get('rexEaseMove').moveTo(gameObject, duration, x, y, ease);
// easemove = scene.plugins.get('rexEaseMove').moveTo(gameObject, duration, x, y, ease, easemove);
  • x, y : End position.
    • Number : End position x/y.
    • String(+=300) : Related position of current position x/y.
    • undefined : Don't move along x/y axis.
  • ease : 'Linear', 'Cubic', 'Elastic', 'Bounce', 'Back' ...
  • easemove : Ease-move behavior.

Move from

var easemove = scene.plugins.get('rexEaseMove').moveFrom(gameObject, duration, x, y);
// var easemove = scene.plugins.get('rexEaseMove').moveFrom(gameObject, duration, x, y, ease);
// easemove = scene.plugins.get('rexEaseMove').moveFrom(gameObject, duration, x, y, ease, easemove);
  • x, y : Start position.
    • Number : Start position x/y.
    • String(-=300) : Related position of current position x/y.
    • undefined : Don't move along x/y axis.
  • ease : 'Linear', 'Cubic', 'Elastic', 'Bounce', 'Back' ...
  • easemove : Ease-move behavior.

Events

See Events of tween task

  • Move completes or is stopped.
    easemove.on('complete', function(gameObject, easemove){
    
    }, scope);