Warp
Introduction¶
Warp post processing filter.
- 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('rexwarppipelineplugin', 'https://raw.githubusercontent.com/rexrainbow/phaser3-rex-notes/master/dist/rexwarppipelineplugin.min.js', true);
- Apply effect
- Apply effect to game object
var pipelineInstance = scene.plugins.get('rexwarppipelineplugin').add(gameObject, config);
- Apply effect to camera
var pipelineInstance = scene.plugins.get('rexwarppipelineplugin').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 WarpPipelinePlugin from 'phaser3-rex-plugins/plugins/warppipeline-plugin.js'; var config = { // ... plugins: { global: [{ key: 'rexWarpPipeline', plugin: WarpPipelinePlugin, start: true }, // ... ] } // ... }; var game = new Phaser.Game(config);
- Apply effect
- Apply effect to game object
var pipelineInstance = scene.plugins.get('rexWarpPipeline').add(gameObject, config);
- Apply effect to camera
var pipelineInstance = scene.plugins.get('rexWarpPipeline').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 WarpPostFx from 'phaser3-rex-plugins/plugins/warppipeline.js'; var config = { // ... pipeline: [WarpPostFx] // ... }; var game = new Phaser.Game(config);
- Apply effect
- Apply effect to game object
gameObject.setPostPipeline(WarpPostFx);
- Apply effect to camera
camera.setPostPipeline(WarpPostFx);
- Apply effect to game object
Apply effect¶
-
Apply effect to game object. A game object only can add 1 warp effect.
var pipelineInstance = scene.plugins.get('rexWarpPipeline').add(gameObject, { // frequencyX: 10, // frequencyY: 10, // amplitudeX: 10, // amplitudeY: 10, // speedX: 0, // speedY: 0, // speedEnable: // name: 'rexWarpPostFx' });
frequencyX
,frequencyY
: Horizontal/vertical frequency, in pixel.amplitudeX
,amplitudeY
: Horizontal/vertical amplitude, in pixel.speedX
,speedY
: Horizontal/vertical speed.speedEnable
true
: Enable speed. Default value ifspeedX
orspeedY
is not0
.false
: Disable speed. Default value ifspeedX
andspeedY
are both0
.
-
Apply effect to camera. A camera only can add 1 warp effect.
var pipelineInstance = scene.plugins.get('rexWarpPipeline').add(camera, config);
Remove effect¶
- Remove effect from game object
scene.plugins.get('rexWarpPipeline').remove(gameObject);
- Remove effect from camera
scene.plugins.get('rexWarpPipeline').remove(camera);
Get effect¶
- Get effect from game object
var pipelineInstance = scene.plugins.get('rexWarpPipeline').get(gameObject)[0]; // var pipelineInstances = scene.plugins.get('rexWarpPipeline').get(gameObject);
- Get effect from camera
var pipelineInstance = scene.plugins.get('rexWarpPipeline').get(camera)[0]; // var pipelineInstances = scene.plugins.get('rexWarpPipeline').get(camera);
Frequency¶
Horizontal/vertical frequency, in pixel.
- Get
var frequencyX = pipelineInstance.frequencyX; var frequencyY = pipelineInstance.frequencyY;
- Set
or
pipelineInstance.frequencyX = frequencyX; pipelineInstance.frequencyY = frequencyY; // pipelineInstance.frequencyX += value; // pipelineInstance.frequencyY += value;
pipelineInstance.setFrequencyX(frequencyX); pipelineInstance.setFrequencyY(frequencyY); pipelineInstance.setFrequency(frequencyX, frequencyY);
Amplitude¶
Horizontal/vertical amplitude, in pixel.
- Get
var amplitudeX = pipelineInstance.amplitudeX; var amplitudeY = pipelineInstance.amplitudeY;
- Set
or
pipelineInstance.amplitudeX = amplitudeX; pipelineInstance.amplitudeY = amplitudeY; // pipelineInstance.amplitudeX += value; // pipelineInstance.amplitudeY += value;
pipelineInstance.setAmplitudeX(amplitudeX); pipelineInstance.setAmplitudeY(amplitudeY); pipelineInstance.setAmplitude(amplitudeX, amplitudeY);
Speed¶
Horizontal/vertical speed.
- Eanble/resume
pipelineInstance.setSpeedEnable();
- Pause
pipelineInstance.setSpeedEnable(false);
- Get
var speedX = pipelineInstance.speedX; var speedY = pipelineInstance.speedY;
- Set
or
pipelineInstance.speedX = speedX; pipelineInstance.speedY = speedY; // pipelineInstance.speedX += value; // pipelineInstance.speedY += value;
pipelineInstance.setSpeedX(speedX); pipelineInstance.setSpeedY(speedY); pipelineInstance.setSpeed(speedX, speedY);