Outline

Introduction

Outline 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('rexoutlinepipelineplugin', 'https://raw.githubusercontent.com/rexrainbow/phaser3-rex-notes/master/dist/rexoutlinepipelineplugin.min.js', true);
    
  • Create pipeline instance
    var pipelineInstance = scene.plugins.get('rexoutlinepipelineplugin').add(scene, key, config);
    

Import plugin

  • Install rex plugins from npm
    npm i phaser3-rex-plugins
    
  • Install plugin in configuration of game
    import OutlinePipelinePlugin from 'phaser3-rex-plugins/plugins/outlinepipeline-plugin.js';
    var config = {
        // ...
        plugins: {
            global: [{
                key: 'rexOutlinePipeline',
                plugin: OutlinePipelinePlugin,
                start: true
            },
            // ...
            ]
        }
        // ...
    };
    var game = new Phaser.Game(config);
    
  • Create pipeline instance
    var pipelineInstance = scene.plugins.get('rexOutlinePipeline').add(scene, key, config);
    

Import class

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

Apply filter

  1. Create pipeline instance
    var pipelineInstance = scene.plugins.get('rexOutlinePipeline').add(scene, key, {
        // thickness: 3,
        // outlineColor: 0x000000
    });
    
    • thickness : Thickness of outline.
    • outlineColor : Color of outline.
  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.

Thickness

  • Get
    var thickness = pipelineInstance.thickness;
    
  • Set
    pipelineInstance.thickness = thickness;
    // pipelineInstance.thickness += value;
    
    or
    pipelineInstance.setThickness(value);
    

Outline color

  • Get
    var color = pipelineInstance.outlineColor;
    
    • color : Color object.
      • Red: color.red, 0~255.
      • Green: color.green, 0~255.
      • Blue: color.blue, 0~255.
  • Set
    pipelineInstance.setOutlineColor(value);
    
    pipelineInstance.outlineColor = value;
    
    • value : A number 0xRRGGBB, or a JSON object {r:255, g:255, b:255}