Barrel
Note
Phaser3.60 has a built-in barrel effect.
Introduction¶
Barrel post processing filter. Reference
- Author: Rex
- A post-fx shader effect
WebGL only
Only work in WebGL render mode.
Live demos¶
Usage¶
Install plugin¶
Load minify file¶
- Load plugin (minify file) in preload stage
scene.load.plugin('rexbarrelpipelineplugin', 'https://raw.githubusercontent.com/rexrainbow/phaser3-rex-notes/master/dist/rexbarrelpipelineplugin.min.js', true);
- Apply effect
- Apply effect to game object
var pipelineInstance = scene.plugins.get('rexbarrelpipelineplugin').add(gameObject, config);
- Apply effect to camera
var pipelineInstance = scene.plugins.get('rexbarrelpipelineplugin').add(camera, config);
- Apply effect to game object
Import plugin¶
- Install rex plugins from npm
npm i phaser3-rex-plugins
- Install plugin in configuration of game
import BarrelPipelinePlugin from 'phaser3-rex-plugins/plugins/barrelpipeline-plugin.js'; var config = { // ... plugins: { global: [{ key: 'rexBarrelPipeline', plugin: BarrelPipelinePlugin, start: true }, // ... ] } // ... }; var game = new Phaser.Game(config);
- Apply effect
- Apply effect to game object
var pipelineInstance = scene.plugins.get('rexBarrelPipeline').add(gameObject, config);
- Apply effect to camera
var pipelineInstance = scene.plugins.get('rexBarrelPipeline').add(camera, config);
- Apply effect to game object
Import class¶
- Install rex plugins from npm
npm i phaser3-rex-plugins
- Add to game config
import BarrelPostFx from 'phaser3-rex-plugins/plugins/barrelpipeline.js'; var config = { // ... pipeline: [BarrelPostFx] // ... }; var game = new Phaser.Game(config);
- Apply effect
- Apply effect to game object
gameObject.setPostPipeline(BarrelPostFx);
- Apply effect to camera
camera.setPostPipeline(BarrelPostFx);
- Apply effect to game object
Apply effect¶
- Apply effect to game object. A game object only can add 1 barrel effect.
var pipelineInstance = scene.plugins.get('rexBarrelPipeline').add(gameObject, { // shrink: false, // center: { // x: windowWidth / 2, // y: windowHeight / 2 //} // radius: 0, // power: 0.5, // intensity: 1, // name: 'rexBarrelPostFx' });
shrink
:false
: Fish-eye effecttrue
: Anti fish-eye effect.
center.x
,center.y
: Local position of barrel center.radius
: Barrel radius.power
: 0~1.intensity
: 0(original) ~ 1(barrel). Default value is1
.
- Apply effect to camera. A camera only can add 1 barrel effect.
var pipelineInstance = scene.plugins.get('rexBarrelPipeline').add(camera, config);
Remove effect¶
- Remove effect from game object
scene.plugins.get('rexBarrelPipeline').remove(gameObject);
- Remove effect from camera
scene.plugins.get('rexBarrelPipeline').remove(camera);
Get effect¶
- Get effect from game object
var pipelineInstance = scene.plugins.get('rexBarrelPipeline').get(gameObject)[0]; // var pipelineInstances = scene.plugins.get('rexBarrelPipeline').get(gameObject);
- Get effect from camera
var pipelineInstance = scene.plugins.get('rexBarrelPipeline').get(camera)[0]; // var pipelineInstances = scene.plugins.get('rexBarrelPipeline').get(camera);
Shrink mode¶
- Get
var shrinkMode = pipelineInstance.shrinkMode;
- Set
pipelineInstance.setShrinkMode(true); // pipelineInstance.setShrinkMode(false);
Radius¶
- Get
var radius = pipelineInstance.radius;
- Set
or
pipelineInstance.radius = radius; // pipelineInstance.radius += value;
pipelineInstance.setRadius(radius);
Power¶
- Get
var power = pipelineInstance.power;
- Set
or
pipelineInstance.power = power;
pipelineInstance.setPower(power);
Intensity¶
- Get
var intensity = pipelineInstance.intensity;
- Set
or
pipelineInstance.intensity = intensity; // pipelineInstance.intensity += value;
pipelineInstance.setIntensity(radius);
intensity
: 0(original) ~ 1(barrel)
Center position¶
Default value is center of window.
- Get
var x = pipelineInstance.centerX; var y = pipelineInstance.centerY;
- Set
or
pipelineInstance.centerX = x; pipelineInstance.centerY = y;
pipelineInstance.setCenter(x, y); // pipelineInstance.setCenter(); // set to center of window