/**
 * Created by Largoyle on 12/04/2014.
 */

/// <reference path="H:/Webpages/LudumDare/LD30/_assets/phaser/build/phaser.d.ts" />

module LEesLD30 {

    export class MainMenu extends Phaser.State {

//        background: Phaser.Sprite;
        myLogo: Phaser.Sprite;
        myTitle: Phaser.Sprite;

        create() {

            // load title text
            this.myTitle = this.add.sprite(this.world.centerX, this.world.centerY*0.75, 'titletext');
            this.myTitle.anchor.setTo(0.5, 0.5);
            this.myTitle.alpha = 0;
//            this.myTitle.scale.x = 2;
//            this.myTitle.scale.y = 2;

            // set bkgr color
            this.game.stage.backgroundColor = '#3d3d3d';

            // add logo
            this.myLogo = this.add.sprite(this.world.centerX-145, 150, 'logo');
            // this.myLogo.anchor.setTo(0, 0.5);

            // fade in titletext
            this.add.tween(this.myTitle).to({ alpha: 1}, 1000, Phaser.Easing.Linear.None, true);

            // tween the logo
            this.add.tween(this.myLogo).to({ y: 320 }, 1500, Phaser.Easing.Elastic.Out, true);

            // any user interaction makes it start
            this.input.onDown.addOnce(this.fadeOut, this);
        }

        fadeOut() {

            this.add.tween(this.myTitle).to({ alpha: 0 }, 800, Phaser.Easing.Linear.None, true);
            var tween = this.add.tween(this.myLogo).to({ y: 800 }, 1000, Phaser.Easing.Linear.None, true);

            tween.onComplete.add(this.startGame, this);

        }

        startGame() {

            this.game.state.start('Level1', true, false);

        }

    }

}

