Interception
Introduction¶
Predict the intersection position of two game objects with constant moving speed.
- Author: Rex
- Behavior of game object
Usage¶
Install plugin¶
Load minify file¶
- Load plugin (minify file) in preload stage
scene.load.plugin('rexinterceptionplugin', 'https://raw.githubusercontent.com/rexrainbow/phaser3-rex-notes/master/dist/rexinterceptionplugin.min.js', true); - Add interception behavior
var interception = scene.plugins.get('rexinterceptionplugin').add(gameObject, config);
Import plugin¶
- Install rex plugins from npm
npm i phaser3-rex-plugins - Install plugin in configuration of game
import InterceptionPlugin from 'phaser3-rex-plugins/plugins/interception-plugin.js'; var config = { // ... plugins: { global: [{ key: 'rexInterception', plugin: InterceptionPlugin, start: true }, // ... ] } // ... }; var game = new Phaser.Game(config); - Add interception behavior
var interception = scene.plugins.get('rexInterception').add(gameObject, config);
Import class¶
- Install rex plugins from npm
npm i phaser3-rex-plugins - Import class
import Interception from 'phaser3-rex-plugins/plugins/interception.js'; - Add interception behavior
var interception = new Interception(gameObject, config);
Create instance¶
var interception = scene.plugins.get('rexInterception').add(gameObject, {
// target: undefined,
// enable: true
});
target: Game object.enable: Settrueto enable predicting.
Target¶
- Set
or
interception.setTarget(gameObject);interception.target = gameObject; - Disalbe
or
interception.setTarget(undefined);interception.target = undefined; - Get
var target = interception.target;
Enable predicting¶
- Enable
interception.setEnable(); - Disable, uses target position as predicted position
interception.setEnable(false);
Predicted result¶
- Predicted position
var position = interception.predictedPosition; // {x, y} - Angle to predicted position
var rotation = interception.predictedAngle; // Angle in radian