import {Sequence} from "../manager/Sequence";
export class End extends Phaser.State {
    music:Phaser.Sound;

    preload() {
        this.game.load.image('end_bg', 'assets/images/end_bg.png');
        this.game.load.image('princess', 'assets/images/princess.png');
        this.game.load.image('credits', 'assets/images/credits.png');
        this.game.load.audio('end_music', 'assets/music/end.ogg');
    }

    create() {
        this.game.stage.backgroundColor = '#fff';
        this.game.add.image(0, 0, 'end_bg');

        this.music = this.game.add.audio('end_music');
        this.music.play();

        var princess = this.game.add.image(this.game.world.centerX, this.game.world.centerY, 'princess');
        princess.anchor.setTo(0.5, 0.5);

        var credits = this.game.add.image(0, 0, 'credits');
        credits.position.y += this.game.height;
        credits.position.x += 100;

        var sequence = new Sequence(this.game);
        sequence.chain(5000, ()=> {
            this.game.add.tween(credits.position).to({y: -240}, 8000, Phaser.Easing.Linear.None, true);
        });
    }

    shutdown() {
        this.music.stop();
    }
}