melonjs 10.8.0 → 10.11.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE.md +1 -1
- package/README.md +32 -25
- package/dist/melonjs.js +1833 -2267
- package/dist/melonjs.min.js +4 -4
- package/dist/melonjs.module.d.ts +642 -1416
- package/dist/melonjs.module.js +1778 -2237
- package/package.json +16 -16
- package/src/audio/audio.js +0 -1
- package/src/camera/camera2d.js +1 -16
- package/src/entity/entity.js +1 -4
- package/src/game.js +2 -2
- package/src/geometries/ellipse.js +18 -27
- package/src/geometries/line.js +5 -8
- package/src/geometries/path2d.js +10 -20
- package/src/geometries/poly.js +28 -45
- package/src/geometries/rectangle.js +24 -36
- package/src/geometries/roundrect.js +96 -3
- package/src/index.js +7 -2
- package/src/input/gamepad.js +5 -16
- package/src/input/keyboard.js +1 -9
- package/src/input/pointer.js +0 -1
- package/src/input/pointerevent.js +14 -23
- package/src/lang/deprecated.js +9 -6
- package/src/level/level.js +0 -9
- package/src/level/tiled/TMXGroup.js +0 -4
- package/src/level/tiled/TMXLayer.js +0 -8
- package/src/level/tiled/TMXObject.js +0 -3
- package/src/level/tiled/TMXTile.js +4 -5
- package/src/level/tiled/TMXTileMap.js +1 -7
- package/src/level/tiled/TMXTileset.js +0 -5
- package/src/level/tiled/TMXTilesetGroup.js +1 -4
- package/src/level/tiled/TMXUtils.js +1 -4
- package/src/level/tiled/renderer/TMXHexagonalRenderer.js +2 -3
- package/src/level/tiled/renderer/TMXIsometricRenderer.js +0 -1
- package/src/level/tiled/renderer/TMXRenderer.js +1 -7
- package/src/loader/loader.js +0 -11
- package/src/loader/loadingscreen.js +16 -5
- package/src/math/color.js +10 -30
- package/src/math/math.js +0 -10
- package/src/math/matrix2.js +12 -27
- package/src/math/matrix3.js +1 -22
- package/src/math/observable_vector2.js +0 -29
- package/src/math/observable_vector3.js +0 -29
- package/src/math/vector2.js +3 -40
- package/src/math/vector3.js +4 -41
- package/src/particles/emitter.js +11 -12
- package/src/physics/body.js +1 -1
- package/src/physics/bounds.js +5 -19
- package/src/physics/collision.js +0 -1
- package/src/physics/detector.js +0 -4
- package/src/physics/quadtree.js +0 -7
- package/src/physics/sat.js +3 -3
- package/src/physics/world.js +0 -4
- package/src/plugin/plugin.js +0 -2
- package/src/polyfill/index.js +1 -0
- package/src/polyfill/roundrect.js +237 -0
- package/src/renderable/GUI.js +5 -10
- package/src/renderable/collectable.js +1 -0
- package/src/renderable/container.js +26 -54
- package/src/renderable/dragndrop.js +0 -9
- package/src/renderable/imagelayer.js +3 -7
- package/src/renderable/light2d.js +114 -0
- package/src/renderable/renderable.js +22 -43
- package/src/renderable/sprite.js +13 -25
- package/src/renderable/trigger.js +1 -1
- package/src/state/stage.js +72 -6
- package/src/state/state.js +3 -20
- package/src/system/device.js +14 -53
- package/src/system/event.js +11 -0
- package/src/system/pooling.js +19 -8
- package/src/system/save.js +9 -11
- package/src/system/timer.js +239 -218
- package/src/text/bitmaptextdata.js +1 -4
- package/src/text/glyph.js +2 -2
- package/src/text/text.js +19 -21
- package/src/text/textmetrics.js +0 -2
- package/src/tweens/easing.js +1 -1
- package/src/tweens/interpolation.js +2 -2
- package/src/tweens/tween.js +1 -13
- package/src/utils/agent.js +1 -3
- package/src/utils/array.js +0 -3
- package/src/utils/file.js +0 -2
- package/src/utils/function.js +0 -2
- package/src/utils/string.js +0 -6
- package/src/utils/utils.js +2 -5
- package/src/video/canvas/canvas_renderer.js +76 -103
- package/src/video/renderer.js +43 -50
- package/src/video/{texture.js → texture/atlas.js} +8 -8
- package/src/video/{texture_cache.js → texture/cache.js} +4 -5
- package/src/video/texture/canvas_texture.js +99 -0
- package/src/video/video.js +3 -3
- package/src/video/webgl/glshader.js +0 -5
- package/src/video/webgl/utils/uniforms.js +4 -7
- package/src/video/webgl/webgl_compositor.js +0 -14
- package/src/video/webgl/webgl_renderer.js +73 -97
package/src/system/timer.js
CHANGED
|
@@ -1,96 +1,16 @@
|
|
|
1
1
|
import utils from "./../utils/utils.js";
|
|
2
|
-
import * as event from "
|
|
2
|
+
import * as event from "./event.js";
|
|
3
3
|
import state from "./../state/state.js";
|
|
4
4
|
import { clamp } from "./../math/math.js";
|
|
5
5
|
|
|
6
|
-
//hold element to display fps
|
|
7
|
-
var framecount = 0;
|
|
8
|
-
var framedelta = 0;
|
|
9
|
-
|
|
10
|
-
/* fps count stuff */
|
|
11
|
-
var last = 0;
|
|
12
|
-
var now = 0;
|
|
13
|
-
var delta = 0;
|
|
14
|
-
// for timeout/interval update
|
|
15
|
-
var step =0;
|
|
16
|
-
var minstep = 0;
|
|
17
|
-
|
|
18
|
-
// list of defined timer function
|
|
19
|
-
var timers = [];
|
|
20
|
-
var timerId = 0;
|
|
21
|
-
|
|
22
|
-
/**
|
|
23
|
-
* update
|
|
24
|
-
* @ignore
|
|
25
|
-
*/
|
|
26
|
-
function update(time) {
|
|
27
|
-
last = now;
|
|
28
|
-
now = time;
|
|
29
|
-
delta = (now - last);
|
|
30
|
-
|
|
31
|
-
// fix for negative timestamp returned by wechat or chrome on startup
|
|
32
|
-
if (delta < 0) {
|
|
33
|
-
delta = 0;
|
|
34
|
-
}
|
|
35
|
-
|
|
36
|
-
// get the game tick
|
|
37
|
-
timer.tick = (delta > minstep && timer.interpolation) ? delta / step : 1;
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
updateTimers();
|
|
41
|
-
};
|
|
42
|
-
|
|
43
|
-
/**
|
|
44
|
-
* clear Timers
|
|
45
|
-
* @ignore
|
|
46
|
-
*/
|
|
47
|
-
function clearTimer(timerId) {
|
|
48
|
-
for (var i = 0, len = timers.length; i < len; i++) {
|
|
49
|
-
if (timers[i].timerId === timerId) {
|
|
50
|
-
timers.splice(i, 1);
|
|
51
|
-
break;
|
|
52
|
-
}
|
|
53
|
-
}
|
|
54
|
-
};
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
/**
|
|
58
|
-
* update timers
|
|
59
|
-
* @ignore
|
|
60
|
-
*/
|
|
61
|
-
function updateTimers() {
|
|
62
|
-
for (var i = 0, len = timers.length; i < len; i++) {
|
|
63
|
-
var _timer = timers[i];
|
|
64
|
-
if (!(_timer.pauseable && state.isPaused())) {
|
|
65
|
-
_timer.elapsed += delta;
|
|
66
|
-
}
|
|
67
|
-
if (_timer.elapsed >= _timer.delay) {
|
|
68
|
-
_timer.fn.apply(null, _timer.args);
|
|
69
|
-
if (_timer.repeat === true) {
|
|
70
|
-
_timer.elapsed -= _timer.delay;
|
|
71
|
-
} else {
|
|
72
|
-
timer.clearTimeout(_timer.timerId);
|
|
73
|
-
}
|
|
74
|
-
}
|
|
75
|
-
}
|
|
76
|
-
};
|
|
77
|
-
|
|
78
|
-
// Initialize me.timer on Boot event
|
|
79
|
-
event.on(event.BOOT, () => {
|
|
80
|
-
// reset variables to initial state
|
|
81
|
-
timer.reset();
|
|
82
|
-
now = last = 0;
|
|
83
|
-
// register to the game before update event
|
|
84
|
-
event.on(event.GAME_BEFORE_UPDATE, update);
|
|
85
|
-
});
|
|
86
|
-
|
|
87
|
-
|
|
88
6
|
/**
|
|
7
|
+
* @classdesc
|
|
89
8
|
* a Timer class to manage timing related function (FPS, Game Tick, Time...)
|
|
90
|
-
|
|
9
|
+
* @see {@link timer} the default global timer instance
|
|
91
10
|
*/
|
|
92
|
-
|
|
11
|
+
class Timer {
|
|
93
12
|
|
|
13
|
+
constructor() {
|
|
94
14
|
/**
|
|
95
15
|
* Last game tick value.<br/>
|
|
96
16
|
* Use this value to scale velocities during frame drops due to slow
|
|
@@ -103,7 +23,7 @@ var timer = {
|
|
|
103
23
|
* @name tick
|
|
104
24
|
* @memberof timer
|
|
105
25
|
*/
|
|
106
|
-
tick
|
|
26
|
+
this.tick = 1.0;
|
|
107
27
|
|
|
108
28
|
/**
|
|
109
29
|
* Last measured fps rate.<br/>
|
|
@@ -113,7 +33,7 @@ var timer = {
|
|
|
113
33
|
* @name fps
|
|
114
34
|
* @memberof timer
|
|
115
35
|
*/
|
|
116
|
-
fps
|
|
36
|
+
this.fps = 0;
|
|
117
37
|
|
|
118
38
|
/**
|
|
119
39
|
* Set the maximum target display frame per second
|
|
@@ -124,7 +44,7 @@ var timer = {
|
|
|
124
44
|
* @default 60
|
|
125
45
|
* @memberof timer
|
|
126
46
|
*/
|
|
127
|
-
maxfps
|
|
47
|
+
this.maxfps = 60;
|
|
128
48
|
|
|
129
49
|
/**
|
|
130
50
|
* Enable/disable frame interpolation
|
|
@@ -134,146 +54,247 @@ var timer = {
|
|
|
134
54
|
* @name interpolation
|
|
135
55
|
* @memberof timer
|
|
136
56
|
*/
|
|
137
|
-
interpolation
|
|
57
|
+
this.interpolation = false;
|
|
138
58
|
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
* @memberof timer
|
|
143
|
-
* @ignore
|
|
144
|
-
* @function
|
|
145
|
-
*/
|
|
146
|
-
reset() {
|
|
147
|
-
// set to "now"
|
|
148
|
-
last = now = globalThis.performance.now();
|
|
149
|
-
delta = 0;
|
|
150
|
-
// reset delta counting variables
|
|
151
|
-
framedelta = 0;
|
|
152
|
-
framecount = 0;
|
|
153
|
-
step = Math.ceil(1000 / this.maxfps); // ROUND IT ?
|
|
154
|
-
// define some step with some margin
|
|
155
|
-
minstep = (1000 / this.maxfps) * 1.25; // IS IT NECESSARY?\
|
|
156
|
-
},
|
|
59
|
+
//hold element to display fps
|
|
60
|
+
this.framecount = 0;
|
|
61
|
+
this.framedelta = 0;
|
|
157
62
|
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
* @param {...*} args optional parameters which are passed through to the function specified by fn once the timer expires.
|
|
166
|
-
* @returns {number} The numerical ID of the timer, which can be used later with me.timer.clearTimeout().
|
|
167
|
-
* @function
|
|
168
|
-
* @example
|
|
169
|
-
* // set a timer to call "myFunction" after 1000ms
|
|
170
|
-
* me.timer.setTimeout(myFunction, 1000);
|
|
171
|
-
* // set a timer to call "myFunction" after 1000ms (respecting the pause state) and passing param1 and param2
|
|
172
|
-
* me.timer.setTimeout(myFunction, 1000, true, param1, param2);
|
|
173
|
-
*/
|
|
174
|
-
setTimeout(fn, delay, pauseable, ...args) {
|
|
175
|
-
timers.push({
|
|
176
|
-
fn : fn,
|
|
177
|
-
delay : delay,
|
|
178
|
-
elapsed : 0,
|
|
179
|
-
repeat : false,
|
|
180
|
-
timerId : ++timerId,
|
|
181
|
-
pauseable : pauseable === true || true,
|
|
182
|
-
args : args
|
|
183
|
-
});
|
|
184
|
-
return timerId;
|
|
185
|
-
},
|
|
63
|
+
/* fps count stuff */
|
|
64
|
+
this.last = 0;
|
|
65
|
+
this.now = 0;
|
|
66
|
+
this.delta = 0;
|
|
67
|
+
// for timeout/interval update
|
|
68
|
+
this.step =0;
|
|
69
|
+
this.minstep = 0;
|
|
186
70
|
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
* @memberof timer
|
|
191
|
-
* @param {Function} fn the function to execute
|
|
192
|
-
* @param {number} delay the number of milliseconds (thousandths of a second) on how often to execute the function
|
|
193
|
-
* @param {boolean} [pauseable=true] respects the pause state of the engine.
|
|
194
|
-
* @param {...*} args optional parameters which are passed through to the function specified by fn once the timer expires.
|
|
195
|
-
* @returns {number} The numerical ID of the timer, which can be used later with me.timer.clearInterval().
|
|
196
|
-
* @function
|
|
197
|
-
* @example
|
|
198
|
-
* // set a timer to call "myFunction" every 1000ms
|
|
199
|
-
* me.timer.setInterval(myFunction, 1000);
|
|
200
|
-
* // set a timer to call "myFunction" every 1000ms (respecting the pause state) and passing param1 and param2
|
|
201
|
-
* me.timer.setInterval(myFunction, 1000, true, param1, param2);
|
|
202
|
-
*/
|
|
203
|
-
setInterval(fn, delay, pauseable, ...args) {
|
|
204
|
-
timers.push({
|
|
205
|
-
fn : fn,
|
|
206
|
-
delay : delay,
|
|
207
|
-
elapsed : 0,
|
|
208
|
-
repeat : true,
|
|
209
|
-
timerId : ++timerId,
|
|
210
|
-
pauseable : pauseable === true || true,
|
|
211
|
-
args : args
|
|
212
|
-
});
|
|
213
|
-
return timerId;
|
|
214
|
-
},
|
|
71
|
+
// list of defined timer function
|
|
72
|
+
this.timers = [];
|
|
73
|
+
this.timerId = 0;
|
|
215
74
|
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
utils.function.defer(clearTimer, this, timeoutID);
|
|
225
|
-
},
|
|
75
|
+
// Initialize mtimer on Boot event
|
|
76
|
+
event.on(event.BOOT, () => {
|
|
77
|
+
// reset variables to initial state
|
|
78
|
+
this.reset();
|
|
79
|
+
this.now = this.last = 0;
|
|
80
|
+
// register to the game before update event
|
|
81
|
+
event.on(event.GAME_BEFORE_UPDATE, this.update.bind(this));
|
|
82
|
+
});
|
|
226
83
|
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
}
|
|
84
|
+
// reset timer
|
|
85
|
+
event.on(event.STATE_RESUME, () => {
|
|
86
|
+
this.reset();
|
|
87
|
+
});
|
|
88
|
+
event.on(event.STATE_RESTART, () => {
|
|
89
|
+
this.reset();
|
|
90
|
+
});
|
|
91
|
+
event.on(event.STATE_CHANGE, () => {
|
|
92
|
+
this.reset();
|
|
93
|
+
});
|
|
94
|
+
}
|
|
237
95
|
|
|
238
|
-
/**
|
|
239
|
-
* Return the current timestamp in milliseconds <br>
|
|
240
|
-
* since the game has started or since linux epoch (based on browser support for High Resolution Timer)
|
|
241
|
-
* @name getTime
|
|
242
|
-
* @memberof timer
|
|
243
|
-
* @returns {number}
|
|
244
|
-
* @function
|
|
245
|
-
*/
|
|
246
|
-
getTime() {
|
|
247
|
-
return now;
|
|
248
|
-
},
|
|
249
96
|
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
97
|
+
/**
|
|
98
|
+
* reset time (e.g. usefull in case of pause)
|
|
99
|
+
* @name reset
|
|
100
|
+
* @memberof timer
|
|
101
|
+
* @ignore
|
|
102
|
+
*/
|
|
103
|
+
reset() {
|
|
104
|
+
// set to "now"
|
|
105
|
+
this.last = this.now = globalThis.performance.now();
|
|
106
|
+
this.delta = 0;
|
|
107
|
+
// reset delta counting variables
|
|
108
|
+
this.framedelta = 0;
|
|
109
|
+
this.framecount = 0;
|
|
110
|
+
this.step = Math.ceil(1000 / this.maxfps); // ROUND IT ?
|
|
111
|
+
// define some step with some margin
|
|
112
|
+
this.minstep = (1000 / this.maxfps) * 1.25; // IS IT NECESSARY?\
|
|
113
|
+
}
|
|
260
114
|
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
|
|
115
|
+
/**
|
|
116
|
+
* Calls a function once after a specified delay. See me.timer.setInterval to repeativly call a function.
|
|
117
|
+
* @name setTimeout
|
|
118
|
+
* @memberof timer
|
|
119
|
+
* @param {Function} fn the function you want to execute after delay milliseconds.
|
|
120
|
+
* @param {number} delay the number of milliseconds (thousandths of a second) that the function call should be delayed by.
|
|
121
|
+
* @param {boolean} [pauseable=true] respects the pause state of the engine.
|
|
122
|
+
* @param {...*} args optional parameters which are passed through to the function specified by fn once the timer expires.
|
|
123
|
+
* @returns {number} The numerical ID of the timer, which can be used later with me.timer.clearTimeout().
|
|
124
|
+
* @example
|
|
125
|
+
* // set a timer to call "myFunction" after 1000ms
|
|
126
|
+
* me.timer.setTimeout(myFunction, 1000);
|
|
127
|
+
* // set a timer to call "myFunction" after 1000ms (respecting the pause state) and passing param1 and param2
|
|
128
|
+
* me.timer.setTimeout(myFunction, 1000, true, param1, param2);
|
|
129
|
+
*/
|
|
130
|
+
setTimeout(fn, delay, pauseable, ...args) {
|
|
131
|
+
this.timers.push({
|
|
132
|
+
fn : fn,
|
|
133
|
+
delay : delay,
|
|
134
|
+
elapsed : 0,
|
|
135
|
+
repeat : false,
|
|
136
|
+
timerId : ++this.timerId,
|
|
137
|
+
pauseable : pauseable === true || true,
|
|
138
|
+
args : args
|
|
139
|
+
});
|
|
140
|
+
return this.timerId;
|
|
141
|
+
}
|
|
142
|
+
|
|
143
|
+
/**
|
|
144
|
+
* Calls a function continously at the specified interval. See setTimeout to call function a single time.
|
|
145
|
+
* @name setInterval
|
|
146
|
+
* @memberof timer
|
|
147
|
+
* @param {Function} fn the function to execute
|
|
148
|
+
* @param {number} delay the number of milliseconds (thousandths of a second) on how often to execute the function
|
|
149
|
+
* @param {boolean} [pauseable=true] respects the pause state of the engine.
|
|
150
|
+
* @param {...*} args optional parameters which are passed through to the function specified by fn once the timer expires.
|
|
151
|
+
* @returns {number} The numerical ID of the timer, which can be used later with me.timer.clearInterval().
|
|
152
|
+
* @example
|
|
153
|
+
* // set a timer to call "myFunction" every 1000ms
|
|
154
|
+
* me.timer.setInterval(myFunction, 1000);
|
|
155
|
+
* // set a timer to call "myFunction" every 1000ms (respecting the pause state) and passing param1 and param2
|
|
156
|
+
* me.timer.setInterval(myFunction, 1000, true, param1, param2);
|
|
157
|
+
*/
|
|
158
|
+
setInterval(fn, delay, pauseable, ...args) {
|
|
159
|
+
this.timers.push({
|
|
160
|
+
fn : fn,
|
|
161
|
+
delay : delay,
|
|
162
|
+
elapsed : 0,
|
|
163
|
+
repeat : true,
|
|
164
|
+
timerId : ++this.timerId,
|
|
165
|
+
pauseable : pauseable === true || true,
|
|
166
|
+
args : args
|
|
167
|
+
});
|
|
168
|
+
return this.timerId;
|
|
169
|
+
}
|
|
170
|
+
|
|
171
|
+
/**
|
|
172
|
+
* Clears the delay set by me.timer.setTimeout().
|
|
173
|
+
* @name clearTimeout
|
|
174
|
+
* @memberof timer
|
|
175
|
+
* @param {number} timeoutID ID of the timeout to be cleared
|
|
176
|
+
*/
|
|
177
|
+
clearTimeout(timeoutID) {
|
|
178
|
+
utils.function.defer(this.clearTimer.bind(this), this, timeoutID);
|
|
179
|
+
}
|
|
180
|
+
|
|
181
|
+
/**
|
|
182
|
+
* Clears the Interval set by me.timer.setInterval().
|
|
183
|
+
* @name clearInterval
|
|
184
|
+
* @memberof timer
|
|
185
|
+
* @param {number} intervalID ID of the interval to be cleared
|
|
186
|
+
*/
|
|
187
|
+
clearInterval(intervalID) {
|
|
188
|
+
utils.function.defer(this.clearTimer.bind(this), this, intervalID);
|
|
189
|
+
}
|
|
190
|
+
|
|
191
|
+
/**
|
|
192
|
+
* Return the current timestamp in milliseconds <br>
|
|
193
|
+
* since the game has started or since linux epoch (based on browser support for High Resolution Timer)
|
|
194
|
+
* @name getTime
|
|
195
|
+
* @memberof timer
|
|
196
|
+
* @returns {number}
|
|
197
|
+
*/
|
|
198
|
+
getTime() {
|
|
199
|
+
return this.now;
|
|
200
|
+
}
|
|
201
|
+
|
|
202
|
+
/**
|
|
203
|
+
* Return elapsed time in milliseconds since the last update
|
|
204
|
+
* @name getDelta
|
|
205
|
+
* @memberof timer
|
|
206
|
+
* @returns {number}
|
|
207
|
+
*/
|
|
208
|
+
getDelta() {
|
|
209
|
+
return this.delta;
|
|
210
|
+
}
|
|
211
|
+
|
|
212
|
+
/**
|
|
213
|
+
* compute the actual frame time and fps rate
|
|
214
|
+
* @name computeFPS
|
|
215
|
+
* @ignore
|
|
216
|
+
* @memberof timer
|
|
217
|
+
*/
|
|
218
|
+
countFPS() {
|
|
219
|
+
this.framecount++;
|
|
220
|
+
this.framedelta += this.delta;
|
|
221
|
+
if (this.framecount % 10 === 0) {
|
|
222
|
+
this.fps = clamp(Math.round((1000 * this.framecount) / this.framedelta), 0, this.maxfps);
|
|
223
|
+
this.framedelta = 0;
|
|
224
|
+
this.framecount = 0;
|
|
225
|
+
}
|
|
226
|
+
}
|
|
227
|
+
|
|
228
|
+
/**
|
|
229
|
+
* update
|
|
230
|
+
* @ignore
|
|
231
|
+
*/
|
|
232
|
+
update(time) {
|
|
233
|
+
this.last = this.now;
|
|
234
|
+
this.now = time;
|
|
235
|
+
this.delta = (this.now - this.last);
|
|
236
|
+
|
|
237
|
+
// fix for negative timestamp returned by wechat or chrome on startup
|
|
238
|
+
if (this.delta < 0) {
|
|
239
|
+
this.delta = 0;
|
|
240
|
+
}
|
|
241
|
+
|
|
242
|
+
// get the game tick
|
|
243
|
+
this.tick = (this.delta > this.minstep && this.interpolation) ? this.delta / this.step : 1;
|
|
244
|
+
|
|
245
|
+
this.updateTimers();
|
|
246
|
+
}
|
|
247
|
+
|
|
248
|
+
/**
|
|
249
|
+
* clear Timers
|
|
250
|
+
* @ignore
|
|
251
|
+
*/
|
|
252
|
+
clearTimer(timerId) {
|
|
253
|
+
for (var i = 0, len = this.timers.length; i < len; i++) {
|
|
254
|
+
if (this.timers[i].timerId === timerId) {
|
|
255
|
+
this.timers.splice(i, 1);
|
|
256
|
+
break;
|
|
275
257
|
}
|
|
276
258
|
}
|
|
259
|
+
}
|
|
260
|
+
|
|
261
|
+
|
|
262
|
+
/**
|
|
263
|
+
* update timers
|
|
264
|
+
* @ignore
|
|
265
|
+
*/
|
|
266
|
+
updateTimers() {
|
|
267
|
+
for (var i = 0, len = this.timers.length; i < len; i++) {
|
|
268
|
+
var _timer = this.timers[i];
|
|
269
|
+
if (!(_timer.pauseable && state.isPaused())) {
|
|
270
|
+
_timer.elapsed += this.delta;
|
|
271
|
+
}
|
|
272
|
+
if (_timer.elapsed >= _timer.delay) {
|
|
273
|
+
_timer.fn.apply(null, _timer.args);
|
|
274
|
+
if (_timer.repeat === true) {
|
|
275
|
+
_timer.elapsed -= _timer.delay;
|
|
276
|
+
} else {
|
|
277
|
+
this.clearTimeout(_timer.timerId);
|
|
278
|
+
}
|
|
279
|
+
}
|
|
280
|
+
}
|
|
281
|
+
}
|
|
277
282
|
};
|
|
278
283
|
|
|
284
|
+
/**
|
|
285
|
+
* the default global Timer instance
|
|
286
|
+
* @namespace timer
|
|
287
|
+
* @see Timer
|
|
288
|
+
* @example
|
|
289
|
+
* // set a timer to call "myFunction" after 1000ms
|
|
290
|
+
* timer.setTimeout(myFunction, 1000);
|
|
291
|
+
* // set a timer to call "myFunction" after 1000ms (respecting the pause state) and passing param1 and param2
|
|
292
|
+
* timer.setTimeout(myFunction, 1000, true, param1, param2);
|
|
293
|
+
* // set a timer to call "myFunction" every 1000ms
|
|
294
|
+
* timer.setInterval(myFunction, 1000);
|
|
295
|
+
* // set a timer to call "myFunction" every 1000ms (respecting the pause state) and passing param1 and param2
|
|
296
|
+
* timer.setInterval(myFunction, 1000, true, param1, param2);
|
|
297
|
+
*/
|
|
298
|
+
const timer = new Timer();
|
|
299
|
+
|
|
279
300
|
export default timer;
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import Glyph from "./glyph.js";
|
|
2
2
|
|
|
3
3
|
// bitmap constants
|
|
4
|
-
|
|
4
|
+
const capChars = ["M", "N", "B", "D", "C", "E", "F", "K", "A", "G", "H", "I", "J", "L", "O", "P", "Q", "R", "S", "T", "U", "V", "W", "X", "Y", "Z"];
|
|
5
5
|
|
|
6
6
|
/**
|
|
7
7
|
* Gets the value from a string of pairs.
|
|
@@ -21,7 +21,6 @@ function getValueFromPair(string, pattern) {
|
|
|
21
21
|
* @ignore
|
|
22
22
|
* @name _getFirstGlyph
|
|
23
23
|
* @memberof BitmapTextData
|
|
24
|
-
* @function
|
|
25
24
|
* @param {object} glyphs the map of glyphs, each key is a char code
|
|
26
25
|
* @returns {Glyph}
|
|
27
26
|
*/
|
|
@@ -40,7 +39,6 @@ function getFirstGlyph(glyphs) {
|
|
|
40
39
|
* @ignore
|
|
41
40
|
* @name createSpaceGlyph
|
|
42
41
|
* @memberof BitmapTextData
|
|
43
|
-
* @function
|
|
44
42
|
* @param {object} glyphs the map of glyphs, each key is a char code
|
|
45
43
|
*/
|
|
46
44
|
function createSpaceGlyph(glyphs) {
|
|
@@ -100,7 +98,6 @@ class BitmapTextData {
|
|
|
100
98
|
* This parses the font data text and builds a map of glyphs containing the data for each character
|
|
101
99
|
* @name parse
|
|
102
100
|
* @memberof BitmapTextData
|
|
103
|
-
* @function
|
|
104
101
|
* @param {string} fontData
|
|
105
102
|
*/
|
|
106
103
|
parse(fontData) {
|
package/src/text/glyph.js
CHANGED
package/src/text/text.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import Color from "./../math/color.js";
|
|
2
2
|
import WebGLRenderer from "./../video/webgl/webgl_renderer.js";
|
|
3
|
-
import { renderer as globalRenderer
|
|
3
|
+
import { renderer as globalRenderer } from "./../video/video.js";
|
|
4
4
|
import { trimRight } from "./../utils/string.js";
|
|
5
5
|
import pool from "./../system/pooling.js";
|
|
6
6
|
import Renderable from "./../renderable/renderable.js";
|
|
@@ -17,13 +17,13 @@ import TextMetrics from "./textmetrics.js";
|
|
|
17
17
|
*/
|
|
18
18
|
|
|
19
19
|
|
|
20
|
-
|
|
21
|
-
|
|
20
|
+
const runits = ["ex", "em", "pt", "px"];
|
|
21
|
+
const toPX = [12, 24, 0.75, 1];
|
|
22
22
|
|
|
23
23
|
// return a valid 2d context for Text rendering/styling
|
|
24
24
|
var getContext2d = function (renderer, text) {
|
|
25
25
|
if (text.offScreenCanvas === true) {
|
|
26
|
-
return text.context;
|
|
26
|
+
return text.canvasTexture.context;
|
|
27
27
|
} else {
|
|
28
28
|
return renderer.getFontContext();
|
|
29
29
|
}
|
|
@@ -66,7 +66,8 @@ class Text extends Renderable {
|
|
|
66
66
|
/**
|
|
67
67
|
* defines the color used to draw the font.<br>
|
|
68
68
|
* @public
|
|
69
|
-
* @
|
|
69
|
+
* @member {Color}
|
|
70
|
+
* @name Text#fillStyle
|
|
70
71
|
* @default black
|
|
71
72
|
*/
|
|
72
73
|
if (typeof settings.fillStyle !== "undefined") {
|
|
@@ -83,7 +84,8 @@ class Text extends Renderable {
|
|
|
83
84
|
/**
|
|
84
85
|
* defines the color used to draw the font stroke.<br>
|
|
85
86
|
* @public
|
|
86
|
-
* @
|
|
87
|
+
* @member {Color}
|
|
88
|
+
* @name strokeStyle
|
|
87
89
|
* @default black
|
|
88
90
|
*/
|
|
89
91
|
if (typeof settings.strokeStyle !== "undefined") {
|
|
@@ -190,8 +192,7 @@ class Text extends Renderable {
|
|
|
190
192
|
|
|
191
193
|
if (settings.offScreenCanvas === true) {
|
|
192
194
|
this.offScreenCanvas = true;
|
|
193
|
-
this.
|
|
194
|
-
this.context = this.canvas.getContext("2d");
|
|
195
|
+
this.canvasTexture = pool.pull("CanvasTexture", 2, 2, { offscreenCanvas: true });
|
|
195
196
|
}
|
|
196
197
|
|
|
197
198
|
// instance to text metrics functions
|
|
@@ -206,10 +207,9 @@ class Text extends Renderable {
|
|
|
206
207
|
// free the canvas and potential corresponding texture when deactivated
|
|
207
208
|
if (this.offScreenCanvas === true) {
|
|
208
209
|
globalRenderer.currentCompositor.deleteTexture2D(globalRenderer.currentCompositor.getTexture2D(this.glTextureUnit));
|
|
209
|
-
globalRenderer.cache.delete(this.canvas);
|
|
210
|
-
|
|
211
|
-
this.
|
|
212
|
-
this.canvas = undefined;
|
|
210
|
+
globalRenderer.cache.delete(this.canvasTexture.canvas);
|
|
211
|
+
pool.push(this.canvasTexture);
|
|
212
|
+
this.canvasTexture = undefined;
|
|
213
213
|
this.glTextureUnit = undefined;
|
|
214
214
|
}
|
|
215
215
|
}
|
|
@@ -307,7 +307,7 @@ class Text extends Renderable {
|
|
|
307
307
|
|
|
308
308
|
if (globalRenderer instanceof WebGLRenderer) {
|
|
309
309
|
// invalidate the previous corresponding texture so that it can reuploaded once changed
|
|
310
|
-
this.glTextureUnit = globalRenderer.cache.getUnit(globalRenderer.cache.get(this.canvas));
|
|
310
|
+
this.glTextureUnit = globalRenderer.cache.getUnit(globalRenderer.cache.get(this.canvasTexture.canvas));
|
|
311
311
|
globalRenderer.currentCompositor.unbindTexture2D(null, this.glTextureUnit);
|
|
312
312
|
|
|
313
313
|
if (globalRenderer.WebGLVersion === 1) {
|
|
@@ -318,14 +318,12 @@ class Text extends Renderable {
|
|
|
318
318
|
}
|
|
319
319
|
|
|
320
320
|
// resize the cache canvas if necessary
|
|
321
|
-
if (this.
|
|
322
|
-
this.
|
|
323
|
-
this.canvas.height = height;
|
|
324
|
-
// resizing the canvas will automatically clear its content
|
|
325
|
-
} else {
|
|
326
|
-
this.context.clearRect(0, 0, this.canvas.width, this.canvas.height);
|
|
321
|
+
if (this.canvasTexture.width < width || this.canvasTexture.height < height) {
|
|
322
|
+
this.canvasTexture.resize(width, height);
|
|
327
323
|
}
|
|
328
|
-
|
|
324
|
+
|
|
325
|
+
this.canvasTexture.clear();
|
|
326
|
+
this._drawFont(this.canvasTexture.context, this._text, this.pos.x - this.metrics.x, this.pos.y - this.metrics.y, false);
|
|
329
327
|
}
|
|
330
328
|
|
|
331
329
|
this.isDirty = true;
|
|
@@ -389,7 +387,7 @@ class Text extends Renderable {
|
|
|
389
387
|
|
|
390
388
|
// draw the text
|
|
391
389
|
if (this.offScreenCanvas === true) {
|
|
392
|
-
renderer.drawImage(this.canvas, x, y);
|
|
390
|
+
renderer.drawImage(this.canvasTexture.canvas, x, y);
|
|
393
391
|
} else {
|
|
394
392
|
renderer.drawFont(this._drawFont(renderer.getFontContext(), this._text, x, y, stroke));
|
|
395
393
|
}
|
package/src/text/textmetrics.js
CHANGED
|
@@ -1,10 +1,8 @@
|
|
|
1
1
|
import Bounds from "./../physics/bounds.js";
|
|
2
2
|
import { trimRight } from "./../utils/string.js";
|
|
3
3
|
import Text from "./text.js";
|
|
4
|
-
//import BitmapText from "./bitmaptext.js";
|
|
5
4
|
import setContextStyle from "./textstyle.js";
|
|
6
5
|
|
|
7
|
-
|
|
8
6
|
/**
|
|
9
7
|
* @classdesc
|
|
10
8
|
* a Text Metrics object that contains helper for text manipulation
|
package/src/tweens/easing.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
|
|
1
|
+
/*
|
|
2
2
|
* Tween.js - Licensed under the MIT license
|
|
3
3
|
* https://github.com/tweenjs/tween.js
|
|
4
4
|
*/
|
|
@@ -76,7 +76,7 @@ export let Interpolation = {
|
|
|
76
76
|
return fc( n ) / fc( i ) / fc( n - i );
|
|
77
77
|
|
|
78
78
|
},
|
|
79
|
-
|
|
79
|
+
/* @ignore */
|
|
80
80
|
Factorial: ( function () {
|
|
81
81
|
|
|
82
82
|
var a = [ 1 ];
|