BasicGame Preloader function game this background null this preloadBar

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
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, 'background');
this.back = this.add.sprite(0,0,"background");
this.logo = this.add.sprite( 160,100, "logo");
this.logo.anchor.setTo( 0.5, 0.5);
this.preloadBar = this.add.sprite(35, 300, 'preloaderBar');
// This sets the preloadBar sprite as a loader sprite.
// What that does is automatically crop the sprite from 0 to full-width
// as the files below are loaded in.
this.load.setPreloadSprite(this.preloadBar);
// Here we load the rest of the assets our game needs.
// As this is just a Project Template I've not provided these assets, the lines below won't work as the files themselves will 404, they are just an example of use.
this.load.image('checkers', 'assets/checkers.png');
this.load.spritesheet('bMenuPlay', 'assets/bPlay.png', 156, 45);
this.load.spritesheet('bMenuMore', 'assets/bMoreGames.png',156, 45);
this.load.image("root", "assets/root.png");
this.load.image("Branch", "assets/Branch.png");
this.load.image("leftBranch", "assets/leftBranch.png");
this.load.image("rightBranch", "assets/rightBranch.png");
this.load.image("iconScore", "assets/iconScore.png");
this.load.image("iconBest", "assets/iconBest.png");
this.load.image("gameEnd", "assets/gameEnd.png");
this.load.image("bar", "assets/bar.png");
this.load.image("pause", "assets/pause.png");
},
preload: function () {
this.load.spritesheet('Jack1', 'assets/Jack1.png', 139, 115, 3);
function create () {
var Jack1 = game.add.sprite(100, 100, 'Jack1');
Jack1.animations.add('walk');
Jack1.animations.play('walk', 3, false);
}
},
create: function () {
Phaser.Canvas.setSmoothingEnabled(this.game.context, false);
// 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
this.preloadBar.cropEnabled = false;
// remove if we have music
this.ready = true;
this.game.state.start('MainMenu');
},
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)
{
this.ready = true;
this.game.state.start('MainMenu');
}
}
};