Skip to content

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

Sample code

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);
      

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);
      

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

  • 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
    pipelineInstance.radius = radius;
    // pipelineInstance.radius += value;
    
    or
    pipelineInstance.setRadius(radius);
    

Rotation

  • Get
    var rotation = pipelineInstance.rotation;  // radians
    // var angle = pipelineInstance.angle;     // degrees
    
  • Set
    pipelineInstance.rotation = rotation;
    pipelineInstance.rotation += value;
    // pipelineInstance.angle = angle;
    // pipelineInstance.angle += value;
    
    or
    pipelineInstance.setRotation(rotation);
    // pipelineInstance.setAngle(angle);
    

Center position

Default value is center of window.

  • Get
    var x = pipelineInstance.centerX;
    var y = pipelineInstance.centerY;
    
  • Set
    pipelineInstance.centerX = x;
    pipelineInstance.centerY = y;
    
    or
    pipelineInstance.setCenter(x, y);
    // pipelineInstance.setCenter();   // set to center of window