Skip to content

spikything/phaser-plugin-crt

Folders and files

NameName
Last commit message
Last commit date

Latest commit

ย 

History

24 Commits
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 

Repository files navigation

phaser-plugin-crt

A lightweight CRT post-processing effect for Phaser 3 as a Scene Plugin. WebGL-only; safely no-ops on Canvas. You can see the plugin in action in the game Exovore.

Image

Installation

npm install phaser-plugin-crt

Usage

Import and register as a Scene Plugin:

import Phaser from "phaser";
import { CRTPlugin } from "phaser-plugin-crt";

const config: Phaser.Types.Core.GameConfig = {
  type: Phaser.AUTO,
  plugins: {
    scene: [{ key: "CRTPlugin", plugin: CRTPlugin, mapping: "crt" }],
  },
  scene: [MyScene],
};

new Phaser.Game(config);

In your scene, simply call crt.enable with your options:

export class MyScene extends Phaser.Scene {
  create() {
    // Enable for all cameras
    this.crt.enable({
      curvature: 0.18,
      scanlineIntensity: 0.16,
      wobbleAmp: 0.001,
    });

    // Toggle with a key
    const key = this.input.keyboard?.addKey("P");
    key?.on("down", () => this.crt.toggle());

    // Live tweak
    this.time.addEvent({
      delay: 2000,
      loop: true,
      callback: () => this.crt.update({ wobbleAmp: Math.random() * 0.002 }),
    });

    // Disable for all cameras
    this.crt.disable();
  }
}

Options

  • curvature (0โ€“0.4)
  • scanlineIntensity (0โ€“0.5)
  • scanlineFreq (1.5โ€“4.0)
  • wobbleAmp (0โ€“0.003)
  • wobbleFreq (10โ€“80)
  • vignette (0โ€“1)
  • desaturate (0โ€“1)
  • gamma (0.8โ€“1.2)
  • maskStrength (0โ€“0.1)
  • noise (0โ€“0.3)
  • detune (0โ€“0.05) enables a sweeping horizontal sawtooth displacement

Demo

Open demo/index.html locally or serve the folder.

Test

Run npm test to run a minimal test suite.

Run npm run benchmark to test the plugin's performance. Expect less than 10ms to do 100,000 iterations.

Build

npm i
npm run build

License

MIT ยฉ Spikything.com