-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathPreloader.js
88 lines (69 loc) · 3.75 KB
/
Preloader.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
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
87
88
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(200, 400, '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, swap them for your own.
this.load.image('titlepage', 'starstruck/bgDecom.png');
//this.load.image('playButton', 'starstruck/button_texture_atlas.png');
this.load.atlas('singleBtn', 'starstruck/btns_single.png', 'starstruck/btn_single.json');
this.load.atlas('multiBtn', 'starstruck/btn_multi.png', 'starstruck/btn_single.json');
this.load.atlas('cfgButton', 'starstruck/btn_cfg.png', 'starstruck/btn_single.json');
this.load.atlas('rankButton', 'starstruck/rank.png', 'starstruck/btn_mini.json');
this.load.atlas('menuButton', 'starstruck/MENU.png', 'starstruck/btn_mini.json');
this.load.audio('coletou', ['audio/coletou.wav']);
this.load.audio('menuSong', 'audio/menu.mp3');
this.load.audio('btn-click', 'audio/btn_click.mp3');
this.load.audio('game-Song', 'audio/gameSong.mp3');
this.load.audio('winSong', 'audio/win.mp3');
//this.load.bitmapFont('caslon', 'fonts/caslon.png', 'fonts/caslon.xml');
// + lots of other required assets here
this.load.tilemap('level1', 'starstruck/level1.json', null, Phaser.Tilemap.TILED_JSON);
this.load.spritesheet('dude', 'starstruck/char2.png', 32, 48);
this.load.spritesheet('dudeInv', 'starstruck/char1.png', 32, 48);
this.load.spritesheet('btns', 'starstruck/controles.png', 25, 25);
this.load.spritesheet('items', 'starstruck/items.png', 32, 32);
this.load.image('hudSP', 'starstruck/hud_sp.png');
this.load.image('hudMP', 'starstruck/hud_mp.png');
this.load.image('tiles-1', 'starstruck/teste.png');
this.load.image('starBig', 'starstruck/star2.png');
this.load.image('background', 'starstruck/26.jpg');
this.load.image('cafe', 'starstruck/coffe.png');
this.load.image('computador', 'starstruck/computer.png');
this.load.image('pinguim', 'starstruck/pinguim.png');
this.load.image('som', 'starstruck/som.png');
this.load.image('pula', 'starstruck/pula-pula.png');
this.load.image('roteador', 'starstruck/router.png');
this.load.image('pgBar1', 'starstruck/progress_bar.png');
this.load.image('endBG', 'starstruck/end-bg.png');
//this.load.image('star', 'start/star.png');
},
create: function () {
// 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;
},
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.ready == false) {
this.ready = true;
this.state.start('MainMenu');
}
}
};