class SceneShatterImage extends Phaser.Scene
{
    constructor ()
    {
        super({ key: "SceneShatterImage", active: true });
    }

    preload ()
    {
//        this.load.image("glass", "assets/glass.png");
    }

    init ()
    {
        this.image = this.add.rexShatterImage(966, 590, 'glass');
        this.image.setVisible(false);
        //.shatter()

        // this.debug = this.add.graphics();
        // image.setDebug(this.debug);
    }

    wake ()
    {
        this.scene.wake();
        this.scene.bringToTop();
        this.image.setVisible(true);

        this.time.delayedCall(1500, () => { 
            this.triggerShatter();
        });
    }

    triggerShatter()
    {
        const image = this.image;

        image.shatter(image.x, image.y);
        image.startUpdate();

        image.task = this.tweens.add({
            targets: image.faces,
            alpha: 0,
            angle: function () { return -90 + Math.random() * 180; },
            y: '-=0.5',
            ease: 'Linear',
            duration: 1000,
            //delay: this.tweens.stagger(20),
            repeat: 0,
            yoyo: false,
            onComplete: function () {
                image
                    .stopUpdate()
                    .resetImage()
                    .setVisible(false); 
            }
        });
    }
}