Swirl

Introduction

Swirl post processing filter. Reference

  • Author: Rex
  • A camera filter

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);
    
  • Create pipeline instance
    var pipelineInstance = scene.plugins.get('rexswirlpipelineplugin').add(scene, key, 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);
    
  • Create pipeline instance
    var pipelineInstance = scene.plugins.get('rexSwirlPipeline').add(scene, key, config);
    

Import class

  • Install rex plugins from npm
    npm i phaser3-rex-plugins
    
  • Import class
    import SwirlPipeline from 'phaser3-rex-plugins/plugins/swirlpipeline.js';
    
  • Create pipeline instance
    var pipelineInstance = new SwirlPipeline(scene, key, config);
    

Apply filter

  1. Create pipeline instance
    var pipelineInstance = scene.plugins.get('rexSwirlPipeline').add(scene, key, {
        // center: {
        //    x: windowWidth / 2,
        //    y: windowHeight / 2
        //}
        // radius: 0,
        // rotation: 0,  // or angle: 0
    });
    
  2. Add to render pipeline
    scene.game.renderer.addPipeline(pipelineName, pipelineInstance);
    
  3. Apply filter
    • To camera
      // var camera = scene.cameras.main;
      camera.setRenderToTexture(pipelineName);
      
    • To game object
      gameObject.setPipeline(pipelineName);
      
      • pipelineName : Name of this render pipeline, a string.

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