-
Notifications
You must be signed in to change notification settings - Fork 0
/
preload.js
56 lines (45 loc) · 1.84 KB
/
preload.js
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
var preload = function(game){
console.log("Preloading");
}
var pressAnyKeyText;
WebFontConfig = {
// 'active' means all requested fonts have finished loading
// We set a 1 second delay before calling 'createText'.
// For some reason if we don't the browser cannot render the text the first time it's created.
//active:
// The Google Fonts we want to load (specify as many as you like in the array)
google: {
families: ['Press Start 2P']
}
};
preload.prototype = {
preload: function() {
var barWidth = (this.game.cache.getImage("loading").width) / 2;
var loadingBar = this.add.sprite((this.game.width/2) - barWidth, this.game.height/3, "loading");
// loadingBar.anchor.setTo(0.5,0.5);
this.load.setPreloadSprite(loadingBar, 0);
this.game.load.image('background', 'assets/starfield.jpg');
this.game.load.image('player', 'assets/spaceship.png');
this.game.load.image('laser', 'assets/laser.png');
this.game.load.image('enemy', 'assets/enemyBlue2.png');
this.game.load.script('webfont', '//ajax.googleapis.com/ajax/libs/webfont/1.4.7/webfont.js');
this.game.load.audio('laserAudio', 'assets/laser.ogg');
this.game.load.spritesheet('explosion', 'assets/explosion.png', 64, 64);
this.game.stage.disableVisibilityChange = true;
var delay = this.game.time.events.add(Phaser.Timer.SECOND * 2, this.createText, this);
},
create: function() {
this.game.input.keyboard.onDownCallback = function(e) {
this.game.state.start("TheGame");
};
},
createText: function() {
pressAnyKeyText = this.game.add.text(400, 350, 'Press any key to start', { fontSize: '32px', fill: 'white'});
pressAnyKeyText.font = 'Press Start 2P';
pressAnyKeyText.fontSize = 16;
pressAnyKeyText.anchor.setTo(0.5, 0.5);
},
shutdown: function() {
this.game.input.keyboard.onDownCallback = null;
}
}