Pen Settings

HTML

CSS

CSS Base

Vendor Prefixing

Add External Stylesheets/Pens

Any URL's added here will be added as <link>s in order, and before the CSS in the editor. You can use the CSS from another Pen by using it's URL and the proper URL extention.

+ add another resource

JavaScript

Babel includes JSX processing.

Add External Scripts/Pens

Any URL's added here will be added as <script>s in order, and run before the JavaScript in the editor. You can use the URL of any other Pen and it will include the JavaScript from that Pen.

+ add another resource

Packages

Add Packages

Search for and use JavaScript packages from npm here. By selecting a package, an import statement will be added to the top of the JavaScript editor for this package.

Behavior

Save Automatically?

If active, Pens will autosave every 30 seconds after being saved once.

Auto-Updating Preview

If enabled, the preview panel updates automatically as you code. If disabled, use the "Run" button to update.

Format on Save

If enabled, your code will be formatted when you actively save your Pen. Note: your code becomes un-folded during formatting.

Editor Settings

Code Indentation

Want to change your Syntax Highlighting theme, Fonts and more?

Visit your global Editor Settings.

HTML

              
                <footer><div id=version></div></footer>
              
            
!

CSS

              
                html, body {
  height: 100%;
}

body {
  margin: 0;
  padding: 0;
  background: #222;
  color: #eee;
  font: caption;
}

#version {
  position: absolute;
  left: 5px;
  top: 605px;
}
              
            
!

JS

              
                class Demo extends Phaser.Scene {
    constructor() {
        super({
            key: 'examples'
        })
    }

    preload() { 
        this.load.scenePlugin({
            key: 'rexuiplugin',
            url: 'https://raw.githubusercontent.com/rexrainbow/phaser3-rex-notes/master/dist/rexuiplugin.min.js',
            sceneKey: 'rexUI'
        });      
    }

    create() {
        var mainPanel = createMainPanel(this)
            .setPosition(400, 300)
            .layout()
        //.drawBounds(this.add.graphics(), 0xff0000);
        
        this.add.text(0, 580, 'Click R/G/B color bar to change filling color')
    }

    update() {}
}

var createMainPanel = function (scene) {
    // Create components
    var objectPanel = scene.add.rectangle(0, 0, 200, 200);
    var controller = createController(scene);
    var mainPanel = scene.rexUI.add.sizer({
            orientation: 'x',
        }).add(
            controller, //child
            0, // proportion
            'top', // align
            0, // paddingConfig
            false, // expand
        )
        .add(
            objectPanel, //child
            0, // proportion
            'center', // align
            0, // paddingConfig
            false, // expand
        );

    // Connect events
    var updateFillColor = function () {
        var red = Math.round(controller.getByName('R').getValue(0, 255));
        var green = Math.round(controller.getByName('G').getValue(0, 255));
        var blue = Math.round(controller.getByName('B').getValue(0, 255));
        objectPanel.setFillStyle(Phaser.Display.Color.GetColor(red, green, blue));
    }
    controller.on('valuechange', function () {
        updateFillColor();
    });
    updateFillColor();
    return mainPanel;
};

var createController = function (scene) {
    // Create components
    var redSlider = createSlider(scene, 'R', 0xd50000, 0x9b0000, 0xff5131).setName('R');
    var greenSlider = createSlider(scene, 'G', 0x00c853, 0x009624, 0x5efc82).setName('G');
    var blueSlider = createSlider(scene, 'B', 0x304ffe, 0x0026ca, 0x7a7cff).setName('B');
    var controlPanel = scene.rexUI.add.sizer({
            orientation: 'y',
        })
        .add(
            redSlider, //child
            0, // proportion
            'center', // align
            0, // paddingConfig
            true, // expand
        )
        .add(
            greenSlider, //child
            0, // proportion
            'center', // align
            0, // paddingConfig
            true, // expand
        )
        .add(
            blueSlider, //child
            0, // proportion
            'center', // align
            0, // paddingConfig
            true, // expand
        );

    // Connect events
    redSlider.on('valuechange', function () {
        this.emit('valuechange');
    }, controlPanel);
    greenSlider.on('valuechange', function () {
        this.emit('valuechange');
    }, controlPanel);
    blueSlider.on('valuechange', function () {
        this.emit('valuechange');
    }, controlPanel);
    return controlPanel;
};

var createSlider = function (scene, colorText, colorPrimary, colorDark, colorLight) {
    return scene.rexUI.add.numberBar({
        background: scene.rexUI.add.roundRectangle(0, 0, 0, 0, 0, colorDark),

        icon: scene.add.text(0, 0, colorText, {
            fontSize: 18
        }),

        slider: {
            track: scene.rexUI.add.roundRectangle(0, 0, 0, 0, 10, colorPrimary),
            indicator: scene.rexUI.add.roundRectangle(0, 0, 0, 0, 10, colorLight),
            input: 'click',
            easeValue: { duration: 250 },
            width: 100, // Fixed width
        },

        space: {
            left: 10,
            right: 10,
            top: 10,
            bottom: 10,

            icon: 10,
            slider: 10,
        },

        value: Math.random()
    })
}

var config = {
    type: Phaser.AUTO,
    parent: 'phaser-example',
    width: 800,
    height: 600,
    scene: Demo
};

var game = new Phaser.Game(config);
              
            
!
999px

Console