JSFiddle - React, Tailwind, and code Playground

by shiqangpan

HTML

<script src="https://cdn.jsdelivr.net/npm/[email protected]/dist/phaser.js"></script>

CSS

body { margin: 0; }
canvas { width: 100%; height: 100% }

JavaScript

class Example extends Phaser.Scene
{
    constructor ()
    {
        super();
    }

    preload ()
    {
        this.load.spritesheet('brawler', 'https://raw.githubusercontent.com/photonstorm/phaser3-examples/master/public/assets/animations/brawler48x48.png', { frameWidth: 48, frameHeight: 48 });
        this.load.image('grid', 'https://raw.githubusercontent.com/photonstorm/phaser3-examples/master/public/assets/textures/grid-ps2.png');
    }

    create ()
    {
        // Text section
        this.add.tileSprite(400, 300, 800, 600, 'grid');

        this.add.image(0, 0, 'brawler', '__BASE').setOrigin(0, 0);

        this.add.grid(0, 0, 192, 384, 48, 48).setOrigin(0, 0).setOutlineStyle(0x00ff00);

        this.add.text(200, 24, '<- walk', { color: '#00ff00' }).setOrigin(0, 0.5);
        this.add.text(200, 72, '<- idle', { color: '#00ff00' }).setOrigin(0, 0.5);
        this.add.text(200, 120, '<- kick', { color: '#00ff00' }).setOrigin(0, 0.5);
        this.add.text(200, 168, '<- punch', { color: '#00ff00' }).setOrigin(0, 0.5);
        this.add.text(200, 216, '<- jump', { color: '#00ff00' }).setOrigin(0, 0.5);
        this.add.text(200, 264, '<- jump kick', { color: '#00ff00' }).setOrigin(0, 0.5);
        this.add.text(200, 312, '<- win', { color: '#00ff00' }).setOrigin(0, 0.5);
        this.add.text(200, 360, '<- die', { color: '#00ff00' }).setOrigin(0, 0.5);
        this.add.text(48, 440, 'Click to change animation', { color: '#00ff00' });
        const current = this.add.text(48, 460, 'Playing: walk', { color: '#00ff00' });

        // Animation set
        this.anims.create({
            key: 'walk',
            frames: this.anims.generateFrameNumbers('brawler', { frames: [ 0, 1, 2, 3 ] }),
            frameRate: 8,
            repeat: -1
        });

        this.anims.create({
            key: 'idle',
            frames: this.anims.generateFrameNumbers('brawler', { frames: [ 5, 6, 7, 8 ] }),
            frameRate: 8,
            repeat: -1
        });

   ...