Get Pixel From Dynamic Texture

Demonstrates how to retrieve color data from a specific coordinate within a Dynamic Texture using the snapshotPixel method.

Get Pixel From Dynamic Texture, running
800 × 600
GitHub
class Example extends Phaser.Scene
{
    constructor ()
    {
        super();
    }

    preload ()
    {
        this.load.setBaseURL('https://cdn.phaserfiles.com/v410');
        this.load.image('wheel', 'assets/pics/large-color-wheel.png');
    }

    create ()
    {
        const texture = this.textures.addDynamicTexture('wheelTexture', 800, 600)

        //  Draw the color wheel to our texture
        texture.stamp('wheel', null, 400, 300).render();

        //  Now add the finished texture to a Sprite
        this.add.sprite(400, 300, 'wheelTexture');

        //  Add a Rectangle so we can show the color we've grabbed
        const rect = this.add.rectangle(10, 10, 128, 128, 0xffffff).setOrigin(0, 0);

        const callback = (color) => {

            rect.setFillStyle(color.color);

        };

        this.input.on('pointerdown', pointer => {

            texture.snapshotPixel(pointer.worldX, pointer.worldY, callback);

        });
    }
}

const config = {
    scale: { mode: Phaser.Scale.FIT },
    type: Phaser.AUTO,
    parent: 'game-container',
    width: 800,
    height: 600,
    backgroundColor: '#2d2d6d',
    scene: Example
};

const game = new Phaser.Game(config);

More in Dynamic Textures7 examples