forked from phaserjs/phaser
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathGame.js
More file actions
204 lines (171 loc) · 5.35 KB
/
Copy pathGame.js
File metadata and controls
204 lines (171 loc) · 5.35 KB
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
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
/**
* Phaser.Game
*
* This is where the magic happens. The Game object is the heart of your game,
* providing quick access to common functions and handling the boot process.
*
* "Hell, there are no rules here - we're trying to accomplish something."
* Thomas A. Edison
*
* @package Phaser.Game
* @author Richard Davey <rich@photonstorm.com>
* @copyright 2013 Photon Storm Ltd.
* @license https://github.com/photonstorm/phaser/blob/master/license.txt MIT License
*/
Phaser.Game = function (callbackContext, parent, width, height, preloadCallback, createCallback, updateCallback, renderCallback, destroyCallback) {
if (typeof parent === "undefined") { parent = ''; }
if (typeof width === "undefined") { width = 800; }
if (typeof height === "undefined") { height = 600; }
if (typeof preloadCallback === "undefined") { preloadCallback = null; }
if (typeof createCallback === "undefined") { createCallback = null; }
if (typeof updateCallback === "undefined") { updateCallback = null; }
if (typeof renderCallback === "undefined") { renderCallback = null; }
if (typeof destroyCallback === "undefined") { destroyCallback = null; }
this.id = Phaser.GAMES.push(this) - 1;
this.callbackContext = callbackContext;
this.onPreloadCallback = preloadCallback;
this.onCreateCallback = createCallback;
this.onUpdateCallback = updateCallback;
this.onRenderCallback = renderCallback;
this.onDestroyCallback = destroyCallback;
var _this = this;
if (document.readyState === 'complete' || document.readyState === 'interactive')
{
setTimeout(function () {
return Phaser.GAMES[_this.id].boot(parent, width, height);
});
}
else
{
document.addEventListener('DOMContentLoaded', Phaser.GAMES[_this.id].boot(parent, width, height), false);
window.addEventListener('load', Phaser.GAMES[_this.id].boot(parent, width, height), false);
}
};
Phaser.Game.prototype = {
/**
* Phaser Game ID.
* @type {number}
*/
id: 0,
/**
* Whether load complete loading or not.
* @type {bool}
*/
_loadComplete: false,
/**
* Game is paused?
* @type {bool}
*/
_paused: false,
/**
* The state to be switched to in the next frame.
* @type {State}
*/
_pendingState: null,
/**
* The current State object (defaults to null)
* @type {State}
*/
state: null,
/**
* This will be called when init states. (loading assets...)
* @type {function}
*/
onPreloadCallback: null,
/**
* This will be called when create states. (setup states...)
* @type {function}
*/
onCreateCallback: null,
/**
* This will be called when State is updated, this doesn't happen during load (see onLoadUpdateCallback)
* @type {function}
*/
onUpdateCallback: null,
/**
* This will be called when the State is rendered, this doesn't happen during load (see onLoadRenderCallback)
* @type {function}
*/
onRenderCallback: null,
/**
* This will be called before the State is rendered and before the stage is cleared
* @type {function}
*/
onPreRenderCallback: null,
/**
* This will be called when the State is updated but only during the load process
* @type {function}
*/
onLoadUpdateCallback: null,
/**
* This will be called when the State is rendered but only during the load process
* @type {function}
*/
onLoadRenderCallback: null,
/**
* This will be called when states paused.
* @type {function}
*/
onPausedCallback: null,
/**
* This will be called when the state is destroyed (i.e. swapping to a new state)
* @type {function}
*/
onDestroyCallback: null,
/**
* Whether the game engine is booted, aka available.
* @type {bool}
*/
isBooted: false,
/**
* Is game running or paused?
* @type {bool}
*/
isRunning: false,
/**
* Initialize engine sub modules and start the game.
* @param parent {string} ID of parent Dom element.
* @param width {number} Width of the game screen.
* @param height {number} Height of the game screen.
*/
boot: function (parent, width, height) {
var _this = this;
if (this.isBooted) {
return;
}
if (!document.body) {
setTimeout(function () {
return Phaser.GAMES[_this.id].boot(parent, width, height);
}, 13);
}
else
{
document.removeEventListener('DOMContentLoaded', Phaser.GAMES[_this.id].boot);
window.removeEventListener('load', Phaser.GAMES[_this.id].boot);
console.log('Phaser', Phaser.VERSION, 'alive');
// this.onPause = new Phaser.Signal();
// this.onResume = new Phaser.Signal();
this.device = new Phaser.Device();
this.net = new Phaser.Net(this);
// this.math = new Phaser.GameMath(this);
// this.stage = new Phaser.Stage(this, parent, width, height);
// this.world = new Phaser.World(this, width, height);
// this.add = new Phaser.GameObjectFactory(this);
this.cache = new Phaser.Cache(this);
this.load = new Phaser.Loader(this);
this.time = new Phaser.Time(this);
this.tweens = new Phaser.TweenManager(this);
// this.input = new Phaser.InputManager(this);
// this.sound = new Phaser.SoundManager(this);
this.rnd = new Phaser.RandomDataGenerator([(Date.now() * Math.random()).toString()]);
// this.physics = new Phaser.Physics.PhysicsManager(this);
// this.plugins = new Phaser.PluginManager(this, this);
// this.load.onLoadComplete.add(this.loadComplete, this);
// this.setRenderer(Phaser.Types.RENDERER_CANVAS);
// this.world.boot();
// this.stage.boot();
// this.input.boot();
this.isBooted = true;
}
},
};