class SpriteEx extends Phaser.GameObjects.Sprite
{
    constructor (scene, reel, x, y, key)
    {
        super(scene, x, y, key);
        
        this.scene.add.existing(this);
        this.reel = reel;

        this.isPlaying = false;
    }

    playShakeAnimation() 
    {
        this.scene.tweens.add({
            targets: this,
            x: this.x + 5,  
            y: this.y + 5,  
            ease: 'Power1',
            duration: 40,
            yoyo: true,
            repeat: 20,  
            onComplete: () => {
                   
            }
        });
    }
    
    playAnimation (repeat)
    {
        if (this.anims.currentAnim != null)
        {
            if (repeat != undefined)
            {
                this.anims.currentAnim.repeat = repeat;//stop after first loop
            }

            this.play(this.anims.currentAnim.key, false);
        }

        this.scale(400, 1);

        this.isPlaying = true;
    }

    stopAnimation ()
    {
        this.scene.tweens.killTweensOf(this);

        this.stop();

        if (this.anims.currentAnim != null)
        {
            this.play(this.anims.currentAnim.key, false, 0);
            this.anims.stop();
        }
        
        this.setScale(1.0);
        
        this.isPlaying = false;
    }

    destroyAnimation ()
    {
        this.stopAnimation();

        if (this.anims.currentAnim != null)
        {
            let key = this.anims.currentAnim.key;

            this.anims.animationManager.remove(key);

            this.anims.currentAnim = null;
        }
    }

    setTextureKey (key)
    {
        this.setTexture(key);

        this.setScale(1.0);
    }

    getTextureKey ()
    {
        return this.texture.key;
    }
    
    scale (duration, repeat)
    {
        this.scene.tweens.add({
            targets: this,
            ease: "Linear",
            duration: duration,
            scale: 1.2,
            repeat: repeat,
            yoyo: true,
            callbackScope: this,
            onComplete: function ()
            {
                this.stopAnimation();

                this.reel.animationComplete();
            },
        });
    }

    preUpdate (time, delta)
    {
       super.preUpdate(time, delta);
    }
}