var loadingScreen = {
    preload: function () {
        this.timeLoadOk = -10000000;
        game.stage.backgroundColor = '#2d2d2d';
        
        this.preloadBarTrans = game.add.sprite(game.world.centerX - 340, game.world.centerY - 45, 'fleche3');
        this.preloadBarTrans.alpha = 0.1;
        this.preloadBar = game.add.sprite(game.world.centerX - 340, game.world.centerY - 45, 'fleche3');
        this.preloadBar.alpha = 1;
        this.load.setPreloadSprite(this.preloadBar);
        this.textState = game.add.text(game.world.centerX, 3 * MAX_SCREEN_Y /5, translation.get('loading'));
        this.textState.anchor.set(0.5);
        this.textState.font = 'Revalia';
        this.textState.fontSize = 60;
        this.textState.fill =  '#eecc00';
        
        game.load.image('menu', './assets/datas/images/menus/menu.png');
        game.load.image('button_1', './assets/datas/images/buttons/planche_1.png');
        game.load.image('button_2', './assets/datas/images/buttons/planche_2.png');
        game.load.image('background', './assets/datas/images/background/background.png');
        game.load.image('castle', './assets/datas/images/background/castle.png');
        game.load.image('life', './assets/datas/images/background/life.png');
        game.load.image('life_in', './assets/datas/images/background/life_in.png');
        game.load.image('bulle', './assets/datas/images/background/bulle.png');
        game.load.image('roi', './assets/datas/images/characters/roi.png');
        game.load.image('dragonCorpse', './assets/datas/images/background/dragonCorpse.png');
        game.load.image('Arrow1', './assets/datas/images/gameObjects/flechebleu.png');
        game.load.image('Arrow2', './assets/datas/images/gameObjects/flecheRouge.png');
        game.load.image('Arrow3', './assets/datas/images/gameObjects/petiteFleche3.png');
        game.load.image('pilone1', './assets/datas/images/gameObjects/pilones.png');
        game.load.image('pilone2', './assets/datas/images/gameObjects/pilones2.png');
        game.load.image('pilone3', './assets/datas/images/gameObjects/pilones3.png');
        game.load.image('piloneBrule1', './assets/datas/images/gameObjects/pilonebrule.png');
        game.load.image('piloneBrule2', './assets/datas/images/gameObjects/pilone2brule.png');
        game.load.image('piloneBrule3', './assets/datas/images/gameObjects/pilone3brule.png');
        game.load.spritesheet('archerStandLvl1', './assets/datas/images/characters/archerStandLvl1.png', 100, 150, 124);
        game.load.spritesheet('archerStandLvl2', './assets/datas/images/characters/archerStandLvl2.png', 100, 150, 124);
        game.load.spritesheet('archerStandLvl3', './assets/datas/images/characters/archerStandLvl3.png', 100, 150, 179);
        game.load.spritesheet('littleArcherStandLvl1', './assets/datas/images/characters/littleArcherStandLvl1.png', 100, 150, 74);
        game.load.spritesheet('littleArcherStandLvl2', './assets/datas/images/characters/littleArcherStandLvl2.png', 100, 150, 74);
        game.load.spritesheet('littleArcherMixLvl3', './assets/datas/images/characters/littleArcherMixLvl3.png', 100, 150, 148);
        game.load.spritesheet('dragonHeadStand', './assets/datas/images/characters/dragonHeadStand.png', 164, 205, 180);
        game.load.spritesheet('fireBall', './assets/datas/images/gameObjects/fireBall.png', 200, 110, 11);
        game.load.spritesheet('archerStandMenu', './assets/datas/images/characters/archerStandMenu.png', 250, 375, 124);
        game.load.spritesheet('archerFireLvl1', './assets/datas/images/characters/archerFireLvl1.png', 100, 150, 74);
        game.load.spritesheet('archerFireLvl2', './assets/datas/images/characters/archerFireLvl2.png', 100, 150, 74);
        game.load.spritesheet('explosion', './assets/datas/images/gameObjects/explosion.png', 120, 120, 13);
        
        game.load.audio('sound_menu', './assets/datas/sounds/menu_medieval_city.ogg');
        game.load.audio('sound_game_calm', './assets/datas/sounds/Chant_du_dragon.ogg');
        game.load.audio('sound_clic_wood', './assets/datas/sounds/clic_wood.ogg');
        game.load.audio('epee', './assets/datas/sounds/epee.ogg');
        game.load.audio('fleche', './assets/datas/sounds/fleche.ogg');
        game.load.audio('fleche_leg', './assets/datas/sounds/Arc.ogg');
        game.load.audio('Clairon', './assets/datas/sounds/Clairon.ogg');
        game.load.audio('FireBall', './assets/datas/sounds/FireBall.ogg');
        game.load.audio('hmm', './assets/datas/sounds/hmm.ogg');
        game.load.audio('hmm2', './assets/datas/sounds/hmm1.ogg');
        game.load.audio('Explosion', './assets/datas/sounds/Explosion.ogg');
        game.load.audio('Cri', './assets/datas/sounds/Cri_de_douleur.ogg');
        
        game.load.image('debug_croix', './assets/datas/images/debug/croix.png');
        game.load.image('debug_noTexture', './assets/datas/images/debug/InWork.jpg');
    },
    
    create: function () {
        this.bmd = game.make.bitmapData(MAX_SCREEN_X, MAX_SCREEN_Y);
        this.bmd.fill(0, 0, 0, 0);
        this.blackScreen = game.add.sprite(0, 0, this.bmd);
    },
    
    update: function () {
        
        var TIME_TRANSITION = 3000;
        
        
        if (game.load.isLoading) {
        } else {
            if (this.timeLoadOk === -10000000) {
                this.timeLoadOk = TIME_TRANSITION;
                this.preloadBar.crop(0,0,this.preloadBar.width, this.preloadBar.height);
                this.textState.text = translation.get('let\'s go!');
            }  else if (this.timeLoadOk > 0) {
                this.timeLoadOk -= game.time.elapsed;
                var alpha = 0.8 - (0.8/TIME_TRANSITION * this.timeLoadOk);
                this.bmd.clear();
                this.bmd.fill(0,0,0, alpha);
            } else {
                game.state.start('Menu');
            }
        }
    }
}