Recoder

Introduction

Recorder of T ime-C ommand-R ecorder-P layer, to store commands with time.

  • Author: Rex
  • Member of scene

Live demos

Usage

Sample code

Install plugin

Load minify file

  • Load plugin (minify file) in preload stage
    scene.load.plugin('rextcrpplugin', 'https://raw.githubusercontent.com/rexrainbow/phaser3-rex-notes/master/dist/rextcrpplugin.min.js', true);
    
  • Create instance
    var recorder = scene.plugins.get('rextcrpplugin').addRecorder(scene);
    

Import plugin

  • Install rex plugins from npm
    npm i phaser3-rex-plugins
    
  • Install plugin in configuration of game
    import TCRPPlugin from 'phaser3-rex-plugins/plugins/tcrp-plugin.js';
    var config = {
        // ...
        plugins: {
            global: [{
                key: 'rexTCRP',
                plugin: TCRPPlugin,
                start: true
            },
            // ...
            ]
        }
        // ...
    };
    var game = new Phaser.Game(config);
    
  • Create instance
    var recorder = scene.plugins.get('rexTCRP').addRecorder(scene);
    

Import class

  • Install rex plugins from npm
    npm i phaser3-rex-plugins
    
  • Import class
    import TCRP from 'phaser3-rex-plugins/plugins/tcrp.js';
    
  • Create instance
    var recorder = new TCRP.Recorder(scene, config);
    

Create instance

var recorder = scene.plugins.get('rexTCRP').addRecorder(scene);

Start recording

recorder.start();
// recorder.start(startAt);  // start-at time in ms

Push commands

recorder.addCommand([fnName, param0, param1, ...]);
// recorder.addCommand([command0, command1, ...]);
// recorder.addCommand([fnName, param0, param1, ...], offset);  // time-offset in ms

See also Run commands

Get commands

var commands = recorder.getCommands();        // get a shallow copy of commands
// var commands = recorder.getCommands(true); // get reference of commands

Format of return commands:

[
    [dt, [command]],
    [dt, [command0,command1]],
    ...
]

Pause, Resume, stop recording

recorder.pause();
recorder.resume();
recorder.stop();

Seek elapsed time

recorder.seek(time);   // elapsed time in ms

State of recorder

var isRecording = recorder.isRecording;
var now = recorder.now;

Time-scale

var timeScale = recorder.timeScale;
recorder.timeScale = 0.5;