Swirl
Introduction¶
Swirl 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('rexswirlpipelineplugin', 'https://raw.githubusercontent.com/rexrainbow/phaser3-rex-notes/master/dist/rexswirlpipelineplugin.min.js', true);
- Apply effect
- Apply effect to game object
var pipelineInstance = scene.plugins.get('rexswirlpipelineplugin').add(gameObject, config);
- Apply effect to camera
var pipelineInstance = scene.plugins.get('rexswirlpipelineplugin').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 SwirlPipelinePlugin from 'phaser3-rex-plugins/plugins/swirlpipeline-plugin.js'; var config = { // ... plugins: { global: [{ key: 'rexSwirlPipeline', plugin: SwirlPipelinePlugin, start: true }, // ... ] } // ... }; var game = new Phaser.Game(config);
- Apply effect
- Apply effect to game object
var pipelineInstance = scene.plugins.get('rexSwirlPipeline').add(gameObject, config);
- Apply effect to camera
var pipelineInstance = scene.plugins.get('rexSwirlPipeline').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 SwirlPostFx from 'phaser3-rex-plugins/plugins/swirlpipeline.js'; var config = { // ... pipeline: [SwirlPostFx] // ... }; var game = new Phaser.Game(config);
- Apply effect
- Apply effect to game object
gameObject.setPostPipeline(SwirlPostFx);
- Apply effect to camera
camera.setPostPipeline(SwirlPostFx);
- Apply effect to game object
Apply effect¶
- Apply effect to game object. A game object only can add 1 swirl effect.
var pipelineInstance = scene.plugins.get('rexSwirlPipeline').add(gameObject, { // center: { // x: windowWidth / 2, // y: windowHeight / 2 //} // radius: 0, // rotation: 0, // or angle: 0, // name: 'rexSwirlPostFx' });
center.x
,center.y
: Local position of swirl center.radius
: Swirl radius.rotation
(angle
) : Swirl angle.
- Apply effect to camera. A camera only can add 1 swirl effect.
var pipelineInstance = scene.plugins.get('rexSwirlPipeline').add(camera, config);
Remove effect¶
- Remove effect from game object
scene.plugins.get('rexSwirlPipeline').remove(gameObject);
- Remove effect from camera
scene.plugins.get('rexSwirlPipeline').remove(camera);
Get effect¶
- Get effect from game object
var pipelineInstance = scene.plugins.get('rexSwirlPipeline').get(gameObject)[0]; // var pipelineInstances = scene.plugins.get('rexSwirlPipeline').get(gameObject);
- Get effect from camera
var pipelineInstance = scene.plugins.get('rexSwirlPipeline').get(camera)[0]; // var pipelineInstances = scene.plugins.get('rexSwirlPipeline').get(camera);
Radius¶
- Get
var radius = pipelineInstance.radius;
- Set
or
pipelineInstance.radius = radius; // pipelineInstance.radius += value;
pipelineInstance.setRadius(radius);
Rotation¶
- Get
var rotation = pipelineInstance.rotation; // radians // var angle = pipelineInstance.angle; // degrees
- Set
or
pipelineInstance.rotation = rotation; pipelineInstance.rotation += value; // pipelineInstance.angle = angle; // pipelineInstance.angle += value;
pipelineInstance.setRotation(rotation); // pipelineInstance.setAngle(angle);
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