2013-10-28 23:29:04 +00:00
|
|
|
|
|
|
|
BasicGame.Preloader = function (game) {
|
|
|
|
|
|
|
|
this.background = null;
|
|
|
|
this.preloadBar = null;
|
|
|
|
|
|
|
|
this.ready = false;
|
|
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
BasicGame.Preloader.prototype = {
|
|
|
|
|
|
|
|
preload: function () {
|
|
|
|
|
|
|
|
// These are the assets we loaded in Boot.js
|
|
|
|
// A nice sparkly background and a loading progress bar
|
|
|
|
this.background = this.add.sprite(0, 0, 'preloaderBackground');
|
|
|
|
this.preloadBar = this.add.sprite(300, 400, 'preloaderBar');
|
|
|
|
|
2013-11-06 16:46:21 +00:00
|
|
|
// This sets the preloadBar sprite as a loader sprite.
|
|
|
|
// What that does is automatically crop the sprite from 0 to full-width
|
2013-10-28 23:29:04 +00:00
|
|
|
// as the files below are loaded in.
|
|
|
|
this.load.setPreloadSprite(this.preloadBar);
|
|
|
|
|
2013-11-06 16:46:21 +00:00
|
|
|
// Here we load the rest of the assets our game needs.
|
|
|
|
// As this is just a Project Template I've not provided these assets, swap them for your own.
|
2013-10-28 23:29:04 +00:00
|
|
|
this.load.image('titlepage', 'images/title.jpg');
|
|
|
|
this.load.atlas('playButton', 'images/play_button.png', 'images/play_button.json');
|
|
|
|
this.load.audio('titleMusic', ['audio/main_menu.mp3']);
|
|
|
|
this.load.bitmapFont('caslon', 'fonts/caslon.png', 'fonts/caslon.xml');
|
|
|
|
// + lots of other required assets here
|
|
|
|
|
|
|
|
},
|
|
|
|
|
|
|
|
create: function () {
|
|
|
|
|
2013-11-06 16:46:21 +00:00
|
|
|
// Once the load has finished we disable the crop because we're going to sit in the update loop for a short while as the music decodes
|
2013-10-28 23:29:04 +00:00
|
|
|
this.preloadBar.cropEnabled = false;
|
|
|
|
|
|
|
|
},
|
|
|
|
|
|
|
|
update: function () {
|
|
|
|
|
|
|
|
// You don't actually need to do this, but I find it gives a much smoother game experience.
|
|
|
|
// Basically it will wait for our audio file to be decoded before proceeding to the MainMenu.
|
|
|
|
// You can jump right into the menu if you want and still play the music, but you'll have a few
|
|
|
|
// seconds of delay while the mp3 decodes - so if you need your music to be in-sync with your menu
|
|
|
|
// it's best to wait for it to decode here first, then carry on.
|
|
|
|
|
|
|
|
// If you don't have any music in your game then put the game.state.start line into the create function and delete
|
|
|
|
// the update function completely.
|
|
|
|
|
|
|
|
if (this.cache.isSoundDecoded('titleMusic') && this.ready == false)
|
|
|
|
{
|
2013-11-06 16:46:21 +00:00
|
|
|
this.ready = true;
|
2014-02-25 14:46:48 +00:00
|
|
|
this.state.start('MainMenu');
|
2013-10-28 23:29:04 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
};
|