-
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Scene_Base.js
325 lines (298 loc) · 7.07 KB
/
Scene_Base.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
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
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
//=============================================================================
/**
* The Superclass of all scene within the game.
*
* @class Scene_Base
* @constructor
* @extends Stage
*/
function Scene_Base() {
this.initialize.apply(this, arguments);
}
Scene_Base.prototype = Object.create(Stage.prototype);
Scene_Base.prototype.constructor = Scene_Base;
/**
* Create a instance of Scene_Base.
*
* @instance
* @memberof Scene_Base
*/
Scene_Base.prototype.initialize = function() {
Stage.prototype.initialize.call(this);
this._active = false;
this._fadeSign = 0;
this._fadeDuration = 0;
this._fadeSprite = null;
this._imageReservationId = Utils.generateRuntimeId();
};
/**
* Attach a reservation to the reserve queue.
*
* @method attachReservation
* @instance
* @memberof Scene_Base
*/
Scene_Base.prototype.attachReservation = function() {
ImageManager.setDefaultReservationId(this._imageReservationId);
};
/**
* Remove the reservation from the Reserve queue.
*
* @method detachReservation
* @instance
* @memberof Scene_Base
*/
Scene_Base.prototype.detachReservation = function() {
ImageManager.releaseReservation(this._imageReservationId);
};
/**
* Create the components and add them to the rendering process.
*
* @method create
* @instance
* @memberof Scene_Base
*/
Scene_Base.prototype.create = function() {
};
/**
* Returns whether the scene is active or not.
*
* @method isActive
* @instance
* @memberof Scene_Base
* @return {Boolean} return true if the scene is active
*/
Scene_Base.prototype.isActive = function() {
return this._active;
};
/**
* Return whether the scene is ready to start or not.
*
* @method isReady
* @instance
* @memberof Scene_Base
* @return {Boolean} Return true if the scene is ready to start
*/
Scene_Base.prototype.isReady = function() {
return ImageManager.isReady();
};
/**
* Start the scene processing.
*
* @method start
* @instance
* @memberof Scene_Base
*/
Scene_Base.prototype.start = function() {
this._active = true;
};
/**
* Update the scene processing each new frame.
*
* @method update
* @instance
* @memberof Scene_Base
*/
Scene_Base.prototype.update = function() {
this.updateFade();
this.updateChildren();
};
/**
* Stop the scene processing.
*
* @method stop
* @instance
* @memberof Scene_Base
*/
Scene_Base.prototype.stop = function() {
this._active = false;
};
/**
* Return whether the scene is busy or not.
*
* @method isBusy
* @instance
* @memberof Scene_Base
* @return {Boolean} Return true if the scene is currently busy
*/
Scene_Base.prototype.isBusy = function() {
return this._fadeDuration > 0;
};
/**
* Terminate the scene before switching to a another scene.
*
* @method terminate
* @instance
* @memberof Scene_Base
*/
Scene_Base.prototype.terminate = function() {
};
/**
* Create the layer for the windows children
* and add it to the rendering process.
*
* @method createWindowLayer
* @instance
* @memberof Scene_Base
*/
Scene_Base.prototype.createWindowLayer = function() {
var width = Graphics.boxWidth;
var height = Graphics.boxHeight;
var x = (Graphics.width - width) / 2;
var y = (Graphics.height - height) / 2;
this._windowLayer = new WindowLayer();
this._windowLayer.move(x, y, width, height);
this.addChild(this._windowLayer);
};
/**
* Add the children window to the windowLayer processing.
*
* @method addWindow
* @instance
* @memberof Scene_Base
*/
Scene_Base.prototype.addWindow = function(window) {
this._windowLayer.addChild(window);
};
/**
* Request a fadeIn screen process.
*
* @method startFadeIn
* @param {Number} [duration=30] The time the process will take for fadeIn the screen
* @param {Boolean} [white=false] If true the fadein will be process with a white color else it's will be black
*
* @instance
* @memberof Scene_Base
*/
Scene_Base.prototype.startFadeIn = function(duration, white) {
this.createFadeSprite(white);
this._fadeSign = 1;
this._fadeDuration = duration || 30;
this._fadeSprite.opacity = 255;
};
/**
* Request a fadeOut screen process.
*
* @method startFadeOut
* @param {Number} [duration=30] The time the process will take for fadeOut the screen
* @param {Boolean} [white=false] If true the fadeOut will be process with a white color else it's will be black
*
* @instance
* @memberof Scene_Base
*/
Scene_Base.prototype.startFadeOut = function(duration, white) {
this.createFadeSprite(white);
this._fadeSign = -1;
this._fadeDuration = duration || 30;
this._fadeSprite.opacity = 0;
};
/**
* Create a Screen sprite for the fadein and fadeOut purpose and
* add it to the rendering process.
*
* @method createFadeSprite
* @instance
* @memberof Scene_Base
*/
Scene_Base.prototype.createFadeSprite = function(white) {
if (!this._fadeSprite) {
this._fadeSprite = new ScreenSprite();
this.addChild(this._fadeSprite);
}
if (white) {
this._fadeSprite.setWhite();
} else {
this._fadeSprite.setBlack();
}
};
/**
* Update the screen fade processing.
*
* @method updateFade
* @instance
* @memberof Scene_Base
*/
Scene_Base.prototype.updateFade = function() {
if (this._fadeDuration > 0) {
var d = this._fadeDuration;
if (this._fadeSign > 0) {
this._fadeSprite.opacity -= this._fadeSprite.opacity / d;
} else {
this._fadeSprite.opacity += (255 - this._fadeSprite.opacity) / d;
}
this._fadeDuration--;
}
};
/**
* Update the children of the scene EACH frame.
*
* @method updateChildren
* @instance
* @memberof Scene_Base
*/
Scene_Base.prototype.updateChildren = function() {
this.children.forEach(function(child) {
if (child.update) {
child.update();
}
});
};
/**
* Pop the scene from the stack array and switch to the
* previous scene.
*
* @method popScene
* @instance
* @memberof Scene_Base
*/
Scene_Base.prototype.popScene = function() {
SceneManager.pop();
};
/**
* Check whether the game should be triggering a gameover.
*
* @method checkGameover
* @instance
* @memberof Scene_Base
*/
Scene_Base.prototype.checkGameover = function() {
if ($gameParty.isAllDead()) {
SceneManager.goto(Scene_Gameover);
}
};
/**
* Slowly fade out all the visual and audio of the scene.
*
* @method fadeOutAll
* @instance
* @memberof Scene_Base
*/
Scene_Base.prototype.fadeOutAll = function() {
var time = this.slowFadeSpeed() / 60;
AudioManager.fadeOutBgm(time);
AudioManager.fadeOutBgs(time);
AudioManager.fadeOutMe(time);
this.startFadeOut(this.slowFadeSpeed());
};
/**
* Return the screen fade speed value.
*
* @method fadeSpeed
* @instance
* @memberof Scene_Base
* @return {Number} Return the fade speed
*/
Scene_Base.prototype.fadeSpeed = function() {
return 24;
};
/**
* Return a slow screen fade speed value.
*
* @method slowFadeSpeed
* @instance
* @memberof Scene_Base
* @return {Number} Return the fade speed
*/
Scene_Base.prototype.slowFadeSpeed = function() {
return this.fadeSpeed() * 2;
};