Tap

Introduction

Get tap/multi-taps events of a game object.

  • Author: Rex
  • Behavior of game object

Live demos

Usage

Sample code

Install plugin

Load minify file

  • Load plugin (minify file) in preload stage
    scene.load.scenePlugin('rexgesturesplugin', 'https://raw.githubusercontent.com/rexrainbow/phaser3-rex-notes/master/dist/rexgesturesplugin.min.js', 'rexGestures', 'rexGestures');
    
  • Add tap input
    var tap = scene.rexGestures.add.tap(config);
    // var tap = scene.rexGestures.add.tap(gameObject, config);
    

Import plugin

  • Install rex plugins from npm
    npm i phaser3-rex-plugins
    
  • Install plugin in configuration of game
    import GesturesPlugin from 'phaser3-rex-plugins/plugins/gestures-plugin.js';
    var config = {
        // ...
        plugins: {
            scene: [{
                key: 'rexGestures',
                plugin: GesturesPlugin,
                mapping: 'rexGestures'
            },
            // ...
            ]
        }
        // ...
    };
    var game = new Phaser.Game(config);
    
  • Add tap input
    var tap = scene.rexGestures.add.tap(config);
    // var tap = scene.rexGestures.add.tap(gameObject, config);
    

Import class

  • Install rex plugins from npm
    npm i phaser3-rex-plugins
    
  • Import class
    import { Tap } from 'phaser3-rex-plugins/plugins/gestures.js';
    
  • Add tap input
    var tap = new Tap(scene, config);
    // var tap = new Tap(gameObject, config);
    

Create instance

  • Pan input
    var tap = scene.rexGestures.add.tap({
        // enable: true,
    
        // time: 250,
        // tapInterval: 200,
        // threshold: 9,
        // tapOffset: 10,
    
        // taps: undefined,
        // minTaps: undefined,
        // maxTaps: undefined,
    });
    
    • enable : Set false to disable input events.
    • time : Max time of the pointer to be down.
    • tapInterval : Max time between the multi-tap taps.
    • threshold : Minimal movement when pointer is down.
    • tapOffset : A multi-tap can be a bit off the initial position.
    • taps : Fire tap event only when taps count reaches this value.
      • undefined : Fire tap event only when tapped end. i.e pointer-up time exceeds tapInterval.
    • minTaps : Fire tap event only when taps count is larger than this value.
      • undefined : Don't check taps count.
    • maxTaps : Fire tap event only when taps count is less than this value.
      • undefined : Don't check taps count.
  • Pan behavior of game object
    var tap = scene.rexGestures.add.tap(gameObject, {
        // enable: true,
    
        // time: 250,
        // tapInterval: 200,
        // threshold: 9,
        // tapOffset: 10,
    
        // taps: undefined,
        // minTaps: undefined,
        // maxTaps: undefined,
    });
    

Enable

  • Get
    var enable = tap.enable;  // enable: true, or false
    
  • Set
    tap.setEnable(enable);  // enable: true, or false
    // tap.enable = enable;
    
  • Toggle
    tap.toggleEnable();
    

Events

Tap

tap.on('tap', function(tap, gameObject, lastPointer){
}, scope);
  • tap.tapsCount : Taps count.
  • gameObject, tap.gameObject : Parent gameobject of this tap behavior.
  • tap.worldX, tap.worldY : World position of first tapping.
  • tap.x, tap.y : Scene position of first tapping.
  • lastPointer : Last touch pointer.
tap.on(tapsCount + 'tap', function(tap, gameObject, lastPointer){
}, scope);
  • tapsCount + 'tap' : 1tap, 2tap, 3tap, etc ...

Tapping start

Each pointer-down will increase taps count and fire tappingstart event.

tap.on('tappingstart', function(tap){
}, scope);

Is tap

var isTapped = tap.isTapped;

Return true if tapped end.