melonjs 13.1.0 → 13.2.1
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/dist/melonjs.js +297 -410
- package/dist/melonjs.min.js +3 -3
- package/dist/melonjs.module.d.ts +185 -387
- package/dist/melonjs.module.js +286 -415
- package/package.json +3 -3
- package/src/geometries/point.js +80 -0
- package/src/index.js +4 -0
- package/src/level/tiled/TMXObject.js +21 -9
- package/src/math/color.js +1 -1
- package/src/physics/body.js +10 -3
- package/src/physics/bounds.js +10 -9
- package/src/polyfill/index.js +2 -2
- package/src/renderable/renderable.js +49 -135
- package/src/renderable/sprite.js +7 -1
- package/src/text/bitmaptext.js +8 -8
- package/src/text/text.js +1 -1
- package/src/text/textmetrics.js +1 -1
- package/src/video/canvas/canvas_renderer.js +31 -4
- package/src/video/renderer.js +8 -50
- package/src/video/video.js +1 -0
- package/src/video/webgl/glshader.js +0 -28
- package/src/video/webgl/webgl_compositor.js +19 -48
- package/src/video/webgl/webgl_renderer.js +36 -112
|
@@ -5,6 +5,7 @@ import Container from "./container.js";
|
|
|
5
5
|
import pool from "./../system/pooling.js";
|
|
6
6
|
import { releaseAllPointerEvents } from "./../input/input.js";
|
|
7
7
|
import { clamp } from "./../math/math.js";
|
|
8
|
+
import Color from "./../math/color.js";
|
|
8
9
|
|
|
9
10
|
/**
|
|
10
11
|
* @classdesc
|
|
@@ -31,21 +32,14 @@ class Renderable extends Rect {
|
|
|
31
32
|
|
|
32
33
|
/**
|
|
33
34
|
* If true then physic collision and input events will not impact this renderable
|
|
34
|
-
* @public
|
|
35
35
|
* @type {boolean}
|
|
36
36
|
* @default true
|
|
37
|
-
* @name isKinematic
|
|
38
|
-
* @memberof Renderable
|
|
39
37
|
*/
|
|
40
38
|
this.isKinematic = true;
|
|
41
39
|
|
|
42
40
|
/**
|
|
43
41
|
* the renderable physic body
|
|
44
|
-
* @public
|
|
45
42
|
* @type {Body}
|
|
46
|
-
* @see Body
|
|
47
|
-
* @name body
|
|
48
|
-
* @memberof Renderable#
|
|
49
43
|
* @example
|
|
50
44
|
* // define a new Player Class
|
|
51
45
|
* class PlayerEntity extends me.Sprite {
|
|
@@ -83,10 +77,7 @@ class Renderable extends Rect {
|
|
|
83
77
|
if (typeof this.currentTransform === "undefined") {
|
|
84
78
|
/**
|
|
85
79
|
* the renderable default transformation matrix
|
|
86
|
-
* @public
|
|
87
80
|
* @type {Matrix2d}
|
|
88
|
-
* @name currentTransform
|
|
89
|
-
* @memberof Renderable#
|
|
90
81
|
*/
|
|
91
82
|
this.currentTransform = pool.pull("Matrix2d");
|
|
92
83
|
}
|
|
@@ -96,20 +87,14 @@ class Renderable extends Rect {
|
|
|
96
87
|
* (G)ame (U)nique (Id)entifier" <br>
|
|
97
88
|
* a GUID will be allocated for any renderable object added <br>
|
|
98
89
|
* to an object container (including the `me.game.world` container)
|
|
99
|
-
* @public
|
|
100
90
|
* @type {string}
|
|
101
|
-
* @name GUID
|
|
102
|
-
* @memberof Renderable
|
|
103
91
|
*/
|
|
104
92
|
this.GUID = undefined;
|
|
105
93
|
|
|
106
94
|
/**
|
|
107
95
|
* an event handler that is called when the renderable leave or enter a camera viewport
|
|
108
|
-
* @public
|
|
109
96
|
* @type {Function}
|
|
110
97
|
* @default undefined
|
|
111
|
-
* @name onVisibilityChange
|
|
112
|
-
* @memberof Renderable#
|
|
113
98
|
* @example
|
|
114
99
|
* this.onVisibilityChange = function(inViewport) {
|
|
115
100
|
* if (inViewport === true) {
|
|
@@ -121,42 +106,30 @@ class Renderable extends Rect {
|
|
|
121
106
|
|
|
122
107
|
/**
|
|
123
108
|
* Whether the renderable object will always update, even when outside of the viewport<br>
|
|
124
|
-
* @public
|
|
125
109
|
* @type {boolean}
|
|
126
110
|
* @default false
|
|
127
|
-
* @name alwaysUpdate
|
|
128
|
-
* @memberof Renderable
|
|
129
111
|
*/
|
|
130
112
|
this.alwaysUpdate = false;
|
|
131
113
|
|
|
132
114
|
/**
|
|
133
115
|
* Whether to update this object when the game is paused.
|
|
134
|
-
* @public
|
|
135
116
|
* @type {boolean}
|
|
136
117
|
* @default false
|
|
137
|
-
* @name updateWhenPaused
|
|
138
|
-
* @memberof Renderable
|
|
139
118
|
*/
|
|
140
119
|
this.updateWhenPaused = false;
|
|
141
120
|
|
|
142
121
|
/**
|
|
143
122
|
* make the renderable object persistent over level changes<br>
|
|
144
|
-
* @public
|
|
145
123
|
* @type {boolean}
|
|
146
124
|
* @default false
|
|
147
|
-
* @name isPersistent
|
|
148
|
-
* @memberof Renderable
|
|
149
125
|
*/
|
|
150
126
|
this.isPersistent = false;
|
|
151
127
|
|
|
152
128
|
/**
|
|
153
129
|
* If true, this renderable will be rendered using screen coordinates,
|
|
154
130
|
* as opposed to world coordinates. Use this, for example, to define UI elements.
|
|
155
|
-
* @public
|
|
156
131
|
* @type {boolean}
|
|
157
132
|
* @default false
|
|
158
|
-
* @name floating
|
|
159
|
-
* @memberof Renderable
|
|
160
133
|
*/
|
|
161
134
|
this.floating = false;
|
|
162
135
|
|
|
@@ -171,11 +144,8 @@ class Renderable extends Rect {
|
|
|
171
144
|
* <br>
|
|
172
145
|
* <i><b>Note:</b> Object created through Tiled will have their anchorPoint set to (0, 0) to match Tiled Level editor implementation.
|
|
173
146
|
* To specify a value through Tiled, use a json expression like `json:{"x":0.5,"y":0.5}`. </i>
|
|
174
|
-
* @public
|
|
175
147
|
* @type {ObservableVector2d}
|
|
176
148
|
* @default <0.5,0.5>
|
|
177
|
-
* @name anchorPoint
|
|
178
|
-
* @memberof Renderable#
|
|
179
149
|
*/
|
|
180
150
|
this.anchorPoint = pool.pull("ObservableVector2d", 0.5, 0.5, { onUpdate: this.onAnchorUpdate, scope: this });
|
|
181
151
|
}
|
|
@@ -183,11 +153,8 @@ class Renderable extends Rect {
|
|
|
183
153
|
/**
|
|
184
154
|
* When enabled, an object container will automatically apply
|
|
185
155
|
* any defined transformation before calling the child draw method.
|
|
186
|
-
* @public
|
|
187
156
|
* @type {boolean}
|
|
188
157
|
* @default true
|
|
189
|
-
* @name autoTransform
|
|
190
|
-
* @memberof Renderable
|
|
191
158
|
* @example
|
|
192
159
|
* // enable "automatic" transformation when the object is activated
|
|
193
160
|
* onActivateEvent: function () {
|
|
@@ -207,30 +174,23 @@ class Renderable extends Rect {
|
|
|
207
174
|
* Set to zero if you do not wish an object to be drawn
|
|
208
175
|
* @see Renderable#setOpacity
|
|
209
176
|
* @see Renderable#getOpacity
|
|
210
|
-
* @public
|
|
211
177
|
* @type {number}
|
|
212
178
|
* @default 1.0
|
|
213
|
-
* @name Renderable#alpha
|
|
214
179
|
*/
|
|
215
180
|
this.alpha = 1.0;
|
|
216
181
|
|
|
217
182
|
/**
|
|
218
183
|
* a reference to the parent object that contains this renderable
|
|
219
|
-
* @public
|
|
220
184
|
* @type {Container|Entity}
|
|
221
185
|
* @default undefined
|
|
222
|
-
* @name Renderable#ancestor
|
|
223
186
|
*/
|
|
224
187
|
this.ancestor = undefined;
|
|
225
188
|
|
|
226
189
|
/**
|
|
227
190
|
* A mask limits rendering elements to the shape and position of the given mask object.
|
|
228
191
|
* So, if the renderable is larger than the mask, only the intersecting part of the renderable will be visible.
|
|
229
|
-
* @public
|
|
230
192
|
* @type {Rect|RoundRect|Polygon|Line|Ellipse}
|
|
231
|
-
* @name mask
|
|
232
193
|
* @default undefined
|
|
233
|
-
* @memberof Renderable#
|
|
234
194
|
* @example
|
|
235
195
|
* // apply a mask in the shape of a Star
|
|
236
196
|
* myNPCSprite.mask = new me.Polygon(myNPCSprite.width / 2, 0, [
|
|
@@ -249,40 +209,19 @@ class Renderable extends Rect {
|
|
|
249
209
|
*/
|
|
250
210
|
this.mask = undefined;
|
|
251
211
|
|
|
252
|
-
/**
|
|
253
|
-
* define a tint for this renderable. a (255, 255, 255) r, g, b value will remove the tint effect.
|
|
254
|
-
* @public
|
|
255
|
-
* @type {Color}
|
|
256
|
-
* @name tint
|
|
257
|
-
* @default (255, 255, 255)
|
|
258
|
-
* @memberof Renderable#
|
|
259
|
-
* @example
|
|
260
|
-
* // add a red tint to this renderable
|
|
261
|
-
* this.tint.setColor(255, 128, 128);
|
|
262
|
-
* // remove the tint
|
|
263
|
-
* this.tint.setColor(255, 255, 255);
|
|
264
|
-
*/
|
|
265
|
-
this.tint = pool.pull("Color", 255, 255, 255, 1.0);
|
|
266
|
-
|
|
267
212
|
/**
|
|
268
213
|
* the blend mode to be applied to this renderable (see renderer setBlendMode for available blend mode)
|
|
269
|
-
* @public
|
|
270
214
|
* @type {string}
|
|
271
|
-
* @name blendMode
|
|
272
215
|
* @default "normal"
|
|
273
216
|
* @see CanvasRenderer#setBlendMode
|
|
274
217
|
* @see WebGLRenderer#setBlendMode
|
|
275
|
-
* @memberof Renderable#
|
|
276
218
|
*/
|
|
277
219
|
this.blendMode = "normal";
|
|
278
220
|
|
|
279
221
|
/**
|
|
280
222
|
* The name of the renderable
|
|
281
|
-
* @public
|
|
282
223
|
* @type {string}
|
|
283
|
-
* @name name
|
|
284
224
|
* @default ""
|
|
285
|
-
* @memberof Renderable
|
|
286
225
|
*/
|
|
287
226
|
this.name = "";
|
|
288
227
|
|
|
@@ -293,8 +232,6 @@ class Renderable extends Rect {
|
|
|
293
232
|
* Position of the Renderable relative to its parent container
|
|
294
233
|
* @public
|
|
295
234
|
* @type {ObservableVector3d}
|
|
296
|
-
* @name pos
|
|
297
|
-
* @memberof Renderable#
|
|
298
235
|
*/
|
|
299
236
|
this.pos = pool.pull("ObservableVector3d", x, y, 0, { onUpdate: this.updateBoundsPos, scope: this});
|
|
300
237
|
}
|
|
@@ -302,9 +239,7 @@ class Renderable extends Rect {
|
|
|
302
239
|
/**
|
|
303
240
|
* when true the renderable will be redrawn during the next update cycle
|
|
304
241
|
* @type {boolean}
|
|
305
|
-
* @name isDirty
|
|
306
242
|
* @default false
|
|
307
|
-
* @memberof Renderable#
|
|
308
243
|
*/
|
|
309
244
|
this.isDirty = false;
|
|
310
245
|
|
|
@@ -323,23 +258,45 @@ class Renderable extends Rect {
|
|
|
323
258
|
|
|
324
259
|
/**
|
|
325
260
|
* Whether the renderable object is floating, or contained in a floating container
|
|
326
|
-
* @public
|
|
327
261
|
* @see Renderable#floating
|
|
328
262
|
* @type {boolean}
|
|
329
|
-
* @name isFloating
|
|
330
|
-
* @memberof Renderable
|
|
331
263
|
*/
|
|
332
264
|
get isFloating() {
|
|
333
265
|
return this.floating === true || (typeof this.ancestor !== "undefined" && this.ancestor.floating === true);
|
|
334
266
|
}
|
|
335
267
|
|
|
268
|
+
/**
|
|
269
|
+
* define a tint for this renderable. a (255, 255, 255) r, g, b value will remove the tint effect.
|
|
270
|
+
* @type {Color}
|
|
271
|
+
* @default (255, 255, 255)
|
|
272
|
+
* @example
|
|
273
|
+
* // add a red tint to this renderable
|
|
274
|
+
* this.tint.setColor(255, 128, 128);
|
|
275
|
+
* // remove the tint
|
|
276
|
+
* this.tint.setColor(255, 255, 255);
|
|
277
|
+
*/
|
|
278
|
+
get tint() {
|
|
279
|
+
if (typeof this._tint === "undefined") {
|
|
280
|
+
this._tint = pool.pull("Color", 255, 255, 255, 1.0);
|
|
281
|
+
}
|
|
282
|
+
return this._tint;
|
|
283
|
+
}
|
|
284
|
+
set tint(value) {
|
|
285
|
+
if (typeof this._tint === "undefined") {
|
|
286
|
+
this._tint = pool.pull("Color", 255, 255, 255, 1.0);
|
|
287
|
+
}
|
|
288
|
+
if (value instanceof Color) {
|
|
289
|
+
this._tint.copy(value);
|
|
290
|
+
} else {
|
|
291
|
+
// string (#RGB, #ARGB, #RRGGBB, #AARRGGBB)
|
|
292
|
+
this._tint.parseCSS(value);
|
|
293
|
+
}
|
|
294
|
+
}
|
|
295
|
+
|
|
336
296
|
/**
|
|
337
297
|
* Whether the renderable object is visible and within the viewport
|
|
338
|
-
* @public
|
|
339
298
|
* @type {boolean}
|
|
340
299
|
* @default false
|
|
341
|
-
* @name inViewport
|
|
342
|
-
* @memberof Renderable
|
|
343
300
|
*/
|
|
344
301
|
get inViewport() {
|
|
345
302
|
return this._inViewport;
|
|
@@ -358,8 +315,6 @@ class Renderable extends Rect {
|
|
|
358
315
|
* @public
|
|
359
316
|
* @see Renderable#flipX
|
|
360
317
|
* @type {boolean}
|
|
361
|
-
* @name isFlippedX
|
|
362
|
-
* @memberof Renderable
|
|
363
318
|
*/
|
|
364
319
|
get isFlippedX() {
|
|
365
320
|
return this._flip.x === true;
|
|
@@ -370,8 +325,6 @@ class Renderable extends Rect {
|
|
|
370
325
|
* @public
|
|
371
326
|
* @see Renderable#flipY
|
|
372
327
|
* @type {boolean}
|
|
373
|
-
* @name isFlippedY
|
|
374
|
-
* @memberof Renderable
|
|
375
328
|
*/
|
|
376
329
|
get isFlippedY() {
|
|
377
330
|
return this._flip.y === true;
|
|
@@ -379,8 +332,6 @@ class Renderable extends Rect {
|
|
|
379
332
|
|
|
380
333
|
/**
|
|
381
334
|
* returns the bounding box for this renderable
|
|
382
|
-
* @name getBounds
|
|
383
|
-
* @memberof Renderable
|
|
384
335
|
* @returns {Bounds} bounding box Rectangle object
|
|
385
336
|
*/
|
|
386
337
|
getBounds() {
|
|
@@ -399,8 +350,6 @@ class Renderable extends Rect {
|
|
|
399
350
|
|
|
400
351
|
/**
|
|
401
352
|
* get the renderable alpha channel value<br>
|
|
402
|
-
* @name getOpacity
|
|
403
|
-
* @memberof Renderable
|
|
404
353
|
* @returns {number} current opacity value between 0 and 1
|
|
405
354
|
*/
|
|
406
355
|
getOpacity() {
|
|
@@ -409,8 +358,6 @@ class Renderable extends Rect {
|
|
|
409
358
|
|
|
410
359
|
/**
|
|
411
360
|
* set the renderable alpha channel value<br>
|
|
412
|
-
* @name setOpacity
|
|
413
|
-
* @memberof Renderable
|
|
414
361
|
* @param {number} alpha opacity value between 0.0 and 1.0
|
|
415
362
|
*/
|
|
416
363
|
setOpacity(alpha) {
|
|
@@ -427,8 +374,6 @@ class Renderable extends Rect {
|
|
|
427
374
|
/**
|
|
428
375
|
* flip the renderable on the horizontal axis (around the center of the renderable)
|
|
429
376
|
* @see Matrix2d#scaleX
|
|
430
|
-
* @name flipX
|
|
431
|
-
* @memberof Renderable
|
|
432
377
|
* @param {boolean} [flip=true] `true` to flip this renderable.
|
|
433
378
|
* @returns {Renderable} Reference to this object for method chaining
|
|
434
379
|
*/
|
|
@@ -441,8 +386,6 @@ class Renderable extends Rect {
|
|
|
441
386
|
/**
|
|
442
387
|
* flip the renderable on the vertical axis (around the center of the renderable)
|
|
443
388
|
* @see Matrix2d#scaleY
|
|
444
|
-
* @name flipY
|
|
445
|
-
* @memberof Renderable
|
|
446
389
|
* @param {boolean} [flip=true] `true` to flip this renderable.
|
|
447
390
|
* @returns {Renderable} Reference to this object for method chaining
|
|
448
391
|
*/
|
|
@@ -454,8 +397,6 @@ class Renderable extends Rect {
|
|
|
454
397
|
|
|
455
398
|
/**
|
|
456
399
|
* multiply the renderable currentTransform with the given matrix
|
|
457
|
-
* @name transform
|
|
458
|
-
* @memberof Renderable
|
|
459
400
|
* @see Renderable#currentTransform
|
|
460
401
|
* @param {Matrix2d} m the transformation matrix
|
|
461
402
|
* @returns {Renderable} Reference to this object for method chaining
|
|
@@ -470,8 +411,6 @@ class Renderable extends Rect {
|
|
|
470
411
|
|
|
471
412
|
/**
|
|
472
413
|
* return the angle to the specified target
|
|
473
|
-
* @name angleTo
|
|
474
|
-
* @memberof Renderable
|
|
475
414
|
* @param {Renderable|Vector2d|Vector3d} target
|
|
476
415
|
* @returns {number} angle in radians
|
|
477
416
|
*/
|
|
@@ -493,8 +432,6 @@ class Renderable extends Rect {
|
|
|
493
432
|
|
|
494
433
|
/**
|
|
495
434
|
* return the distance to the specified target
|
|
496
|
-
* @name distanceTo
|
|
497
|
-
* @memberof Renderable
|
|
498
435
|
* @param {Renderable|Vector2d|Vector3d} target
|
|
499
436
|
* @returns {number} distance
|
|
500
437
|
*/
|
|
@@ -516,8 +453,6 @@ class Renderable extends Rect {
|
|
|
516
453
|
|
|
517
454
|
/**
|
|
518
455
|
* Rotate this renderable towards the given target.
|
|
519
|
-
* @name lookAt
|
|
520
|
-
* @memberof Renderable
|
|
521
456
|
* @param {Renderable|Vector2d|Vector3d} target the renderable or position to look at
|
|
522
457
|
* @returns {Renderable} Reference to this object for method chaining
|
|
523
458
|
*/
|
|
@@ -539,8 +474,6 @@ class Renderable extends Rect {
|
|
|
539
474
|
|
|
540
475
|
/**
|
|
541
476
|
* Rotate this renderable by the specified angle (in radians).
|
|
542
|
-
* @name rotate
|
|
543
|
-
* @memberof Renderable
|
|
544
477
|
* @param {number} angle The angle to rotate (in radians)
|
|
545
478
|
* @param {Vector2d|ObservableVector2d} [v] an optional point to rotate around
|
|
546
479
|
* @returns {Renderable} Reference to this object for method chaining
|
|
@@ -560,8 +493,6 @@ class Renderable extends Rect {
|
|
|
560
493
|
* when rendering. It does not scale the object itself. For example if the renderable
|
|
561
494
|
* is an image, the image.width and image.height properties are unaltered but the currentTransform
|
|
562
495
|
* member will be changed.
|
|
563
|
-
* @name scale
|
|
564
|
-
* @memberof Renderable
|
|
565
496
|
* @param {number} x a number representing the abscissa of the scaling vector.
|
|
566
497
|
* @param {number} [y=x] a number representing the ordinate of the scaling vector.
|
|
567
498
|
* @returns {Renderable} Reference to this object for method chaining
|
|
@@ -575,8 +506,6 @@ class Renderable extends Rect {
|
|
|
575
506
|
|
|
576
507
|
/**
|
|
577
508
|
* scale the renderable around his anchor point
|
|
578
|
-
* @name scaleV
|
|
579
|
-
* @memberof Renderable
|
|
580
509
|
* @param {Vector2d} v scaling vector
|
|
581
510
|
* @returns {Renderable} Reference to this object for method chaining
|
|
582
511
|
*/
|
|
@@ -586,11 +515,7 @@ class Renderable extends Rect {
|
|
|
586
515
|
}
|
|
587
516
|
|
|
588
517
|
/**
|
|
589
|
-
* update function.
|
|
590
|
-
* automatically called by the game manager {@link game}
|
|
591
|
-
* @name update
|
|
592
|
-
* @memberof Renderable
|
|
593
|
-
* @protected
|
|
518
|
+
* update function (automatically called by melonJS).
|
|
594
519
|
* @param {number} dt time since the last update in milliseconds.
|
|
595
520
|
* @returns {boolean} true if the renderable is dirty
|
|
596
521
|
*/
|
|
@@ -601,8 +526,6 @@ class Renderable extends Rect {
|
|
|
601
526
|
/**
|
|
602
527
|
* update the bounding box for this shape.
|
|
603
528
|
* @ignore
|
|
604
|
-
* @name updateBounds
|
|
605
|
-
* @memberof Renderable
|
|
606
529
|
* @returns {Bounds} this shape bounding box Rectangle object
|
|
607
530
|
*/
|
|
608
531
|
updateBounds() {
|
|
@@ -614,8 +537,6 @@ class Renderable extends Rect {
|
|
|
614
537
|
/**
|
|
615
538
|
* update the renderable's bounding rect (private)
|
|
616
539
|
* @ignore
|
|
617
|
-
* @name updateBoundsPos
|
|
618
|
-
* @memberof Renderable
|
|
619
540
|
*/
|
|
620
541
|
updateBoundsPos(newX, newY) {
|
|
621
542
|
var bounds = this.getBounds();
|
|
@@ -646,8 +567,6 @@ class Renderable extends Rect {
|
|
|
646
567
|
|
|
647
568
|
/**
|
|
648
569
|
* return the renderable absolute position in the game world
|
|
649
|
-
* @name getAbsolutePosition
|
|
650
|
-
* @memberof Renderable
|
|
651
570
|
* @returns {Vector2d}
|
|
652
571
|
*/
|
|
653
572
|
getAbsolutePosition() {
|
|
@@ -665,8 +584,6 @@ class Renderable extends Rect {
|
|
|
665
584
|
/**
|
|
666
585
|
* called when the anchor point value is changed
|
|
667
586
|
* @private
|
|
668
|
-
* @name onAnchorUpdate
|
|
669
|
-
* @memberof Renderable
|
|
670
587
|
* @param {number} x the new X value to be set for the anchor
|
|
671
588
|
* @param {number} y the new Y value to be set for the anchor
|
|
672
589
|
*/
|
|
@@ -679,12 +596,10 @@ class Renderable extends Rect {
|
|
|
679
596
|
}
|
|
680
597
|
|
|
681
598
|
/**
|
|
682
|
-
*
|
|
683
|
-
*
|
|
684
|
-
*
|
|
685
|
-
* @
|
|
686
|
-
* @memberof Renderable
|
|
687
|
-
* @protected
|
|
599
|
+
* Prepare the rendering context before drawing (automatically called by melonJS).
|
|
600
|
+
* This will apply any defined transforms, anchor point, tint or blend mode and translate the context accordingly to this renderable position.
|
|
601
|
+
* @see Renderable#draw
|
|
602
|
+
* @see Renderable#postDraw
|
|
688
603
|
* @param {CanvasRenderer|WebGLRenderer} renderer a renderer object
|
|
689
604
|
*/
|
|
690
605
|
preDraw(renderer) {
|
|
@@ -735,10 +650,15 @@ class Renderable extends Rect {
|
|
|
735
650
|
}
|
|
736
651
|
|
|
737
652
|
/**
|
|
738
|
-
*
|
|
739
|
-
*
|
|
740
|
-
*
|
|
741
|
-
*
|
|
653
|
+
* Draw this renderable (automatically called by melonJS).
|
|
654
|
+
* All draw operations for renderable are made respectively
|
|
655
|
+
* to the position or transforms set or applied by the preDraw method.
|
|
656
|
+
* The main draw loop will first call preDraw() to prepare the context for drawing the renderable,
|
|
657
|
+
* then draw() to draw the renderable, and finally postDraw() to clear the context.
|
|
658
|
+
* If you override this method, be mindful about the drawing logic; for example if you draw a shape
|
|
659
|
+
* from the draw method, you should make sure that your draw it at the 0, 0 coordinates.
|
|
660
|
+
* @see Renderable#preDraw
|
|
661
|
+
* @see Renderable#postDraw
|
|
742
662
|
* @param {CanvasRenderer|WebGLRenderer} renderer a renderer instance
|
|
743
663
|
* @param {Camera2d} [viewport] the viewport to (re)draw
|
|
744
664
|
*/
|
|
@@ -747,11 +667,9 @@ class Renderable extends Rect {
|
|
|
747
667
|
}
|
|
748
668
|
|
|
749
669
|
/**
|
|
750
|
-
* restore the rendering context after drawing.
|
|
751
|
-
*
|
|
752
|
-
* @
|
|
753
|
-
* @memberof Renderable
|
|
754
|
-
* @protected
|
|
670
|
+
* restore the rendering context after drawing (automatically called by melonJS).
|
|
671
|
+
* @see Renderable#preDraw
|
|
672
|
+
* @see Renderable#draw
|
|
755
673
|
* @param {CanvasRenderer|WebGLRenderer} renderer a renderer object
|
|
756
674
|
*/
|
|
757
675
|
postDraw(renderer) {
|
|
@@ -773,8 +691,6 @@ class Renderable extends Rect {
|
|
|
773
691
|
/**
|
|
774
692
|
* onCollision callback, triggered in case of collision,
|
|
775
693
|
* when this renderable body is colliding with another one
|
|
776
|
-
* @name onCollision
|
|
777
|
-
* @memberof Renderable
|
|
778
694
|
* @param {ResponseObject} response the collision response object
|
|
779
695
|
* @param {Renderable} other the other renderable touching this one (a reference to response.a or response.b)
|
|
780
696
|
* @returns {boolean} true if the object should respond to the collision (its position and velocity will be corrected)
|
|
@@ -826,9 +742,9 @@ class Renderable extends Rect {
|
|
|
826
742
|
this.mask = undefined;
|
|
827
743
|
}
|
|
828
744
|
|
|
829
|
-
if (typeof this.
|
|
830
|
-
pool.push(this.
|
|
831
|
-
this.
|
|
745
|
+
if (typeof this._tint !== "undefined") {
|
|
746
|
+
pool.push(this._tint);
|
|
747
|
+
this._tint = undefined;
|
|
832
748
|
}
|
|
833
749
|
|
|
834
750
|
this.ancestor = undefined;
|
|
@@ -849,8 +765,6 @@ class Renderable extends Rect {
|
|
|
849
765
|
/**
|
|
850
766
|
* OnDestroy Notification function<br>
|
|
851
767
|
* Called by engine before deleting the object
|
|
852
|
-
* @name onDestroyEvent
|
|
853
|
-
* @memberof Renderable
|
|
854
768
|
*/
|
|
855
769
|
onDestroyEvent() {
|
|
856
770
|
// to be extended !
|
package/src/renderable/sprite.js
CHANGED
|
@@ -3,6 +3,7 @@ import pool from "./../system/pooling.js";
|
|
|
3
3
|
import loader from "./../loader/loader.js";
|
|
4
4
|
import { TextureAtlas } from "./../video/texture/atlas.js";
|
|
5
5
|
import Renderable from "./renderable.js";
|
|
6
|
+
import Color from "../math/color.js";
|
|
6
7
|
|
|
7
8
|
/**
|
|
8
9
|
* @classdesc
|
|
@@ -183,7 +184,12 @@ class Sprite extends Renderable {
|
|
|
183
184
|
}
|
|
184
185
|
|
|
185
186
|
if (typeof (settings.tint) !== "undefined") {
|
|
186
|
-
|
|
187
|
+
if (settings.tint instanceof Color) {
|
|
188
|
+
this.tint.copy(settings.tint);
|
|
189
|
+
} else {
|
|
190
|
+
// string (#RGB, #ARGB, #RRGGBB, #AARRGGBB)
|
|
191
|
+
this.tint.parseCSS(settings.tint);
|
|
192
|
+
}
|
|
187
193
|
}
|
|
188
194
|
|
|
189
195
|
// set the sprite name if specified
|
package/src/text/bitmaptext.js
CHANGED
|
@@ -118,12 +118,7 @@ class BitmapText extends Renderable {
|
|
|
118
118
|
|
|
119
119
|
// apply given fillstyle
|
|
120
120
|
if (typeof settings.fillStyle !== "undefined") {
|
|
121
|
-
|
|
122
|
-
this.fillStyle.setColor(settings.fillStyle);
|
|
123
|
-
} else {
|
|
124
|
-
// string (#RGB, #ARGB, #RRGGBB, #AARRGGBB)
|
|
125
|
-
this.fillStyle.parseCSS(settings.fillStyle);
|
|
126
|
-
}
|
|
121
|
+
this.fillStyle = settings.fillStyle;
|
|
127
122
|
}
|
|
128
123
|
|
|
129
124
|
// update anchorPoint if provided
|
|
@@ -196,7 +191,12 @@ class BitmapText extends Renderable {
|
|
|
196
191
|
return this.tint;
|
|
197
192
|
}
|
|
198
193
|
set fillStyle(value) {
|
|
199
|
-
|
|
194
|
+
if (value instanceof Color) {
|
|
195
|
+
this.tint.copy(value);
|
|
196
|
+
} else {
|
|
197
|
+
// string (#RGB, #ARGB, #RRGGBB, #AARRGGBB)
|
|
198
|
+
this.tint.parseCSS(value);
|
|
199
|
+
}
|
|
200
200
|
}
|
|
201
201
|
|
|
202
202
|
/**
|
|
@@ -253,7 +253,7 @@ class BitmapText extends Renderable {
|
|
|
253
253
|
|
|
254
254
|
for (var i = 0; i < this._text.length; i++) {
|
|
255
255
|
x = lX;
|
|
256
|
-
var string = this._text[i].
|
|
256
|
+
var string = this._text[i].trimEnd();
|
|
257
257
|
// adjust x pos based on alignment value
|
|
258
258
|
var stringWidth = this.metrics.lineWidth(string);
|
|
259
259
|
switch (this.textAlign) {
|
package/src/text/text.js
CHANGED
|
@@ -410,7 +410,7 @@ class Text extends Renderable {
|
|
|
410
410
|
setContextStyle(context, this, stroke);
|
|
411
411
|
|
|
412
412
|
for (var i = 0; i < text.length; i++) {
|
|
413
|
-
var string = text[i].
|
|
413
|
+
var string = text[i].trimEnd();
|
|
414
414
|
// draw the string
|
|
415
415
|
context[stroke ? "strokeText" : "fillText"](string, x, y);
|
|
416
416
|
// add leading space
|
package/src/text/textmetrics.js
CHANGED
|
@@ -91,7 +91,7 @@ class TextMetrics extends Bounds {
|
|
|
91
91
|
this.width = this.height = 0;
|
|
92
92
|
|
|
93
93
|
for (var i = 0; i < strings.length; i++) {
|
|
94
|
-
this.width = Math.max(this.lineWidth(strings[i].
|
|
94
|
+
this.width = Math.max(this.lineWidth(strings[i].trimEnd(), context), this.width);
|
|
95
95
|
this.height += this.lineHeight();
|
|
96
96
|
}
|
|
97
97
|
this.width = Math.ceil(this.width);
|
|
@@ -124,8 +124,10 @@ class CanvasRenderer extends Renderer {
|
|
|
124
124
|
* @memberof CanvasRenderer
|
|
125
125
|
*/
|
|
126
126
|
clear() {
|
|
127
|
-
if (this.settings.transparent) {
|
|
128
|
-
this.
|
|
127
|
+
if (this.settings.transparent === false) {
|
|
128
|
+
var canvas = this.getCanvas();
|
|
129
|
+
var context = this.getContext();
|
|
130
|
+
context.clearRect(0, 0, canvas.width, canvas.height);
|
|
129
131
|
}
|
|
130
132
|
}
|
|
131
133
|
|
|
@@ -136,13 +138,14 @@ class CanvasRenderer extends Renderer {
|
|
|
136
138
|
* @param {Color|string} [color="#000000"] CSS color.
|
|
137
139
|
* @param {boolean} [opaque=false] Allow transparency [default] or clear the surface completely [true]
|
|
138
140
|
*/
|
|
139
|
-
clearColor(color = "#000000", opaque) {
|
|
141
|
+
clearColor(color = "#000000", opaque = false) {
|
|
140
142
|
var canvas = this.getCanvas();
|
|
141
143
|
var context = this.getContext();
|
|
142
144
|
|
|
143
145
|
this.save();
|
|
144
146
|
this.resetTransform();
|
|
145
|
-
context.
|
|
147
|
+
context.globalAlpha = 1;
|
|
148
|
+
context.globalCompositeOperation = opaque === true ? "copy" : "source-over";
|
|
146
149
|
context.fillStyle = (color instanceof Color) ? color.toRGBA() : color;
|
|
147
150
|
this.fillRect(0, 0, canvas.width, canvas.height);
|
|
148
151
|
this.restore();
|
|
@@ -504,6 +507,30 @@ class CanvasRenderer extends Renderer {
|
|
|
504
507
|
this.strokeRoundRect(x, y, width, height, radius, true);
|
|
505
508
|
}
|
|
506
509
|
|
|
510
|
+
/**
|
|
511
|
+
* Stroke a Point at the specified coordinates
|
|
512
|
+
* @name strokePoint
|
|
513
|
+
* @memberof CanvasRenderer
|
|
514
|
+
* @param {number} x
|
|
515
|
+
* @param {number} y
|
|
516
|
+
*/
|
|
517
|
+
strokePoint(x, y) {
|
|
518
|
+
this.strokeLine(x, y, x + 1, y + 1);
|
|
519
|
+
}
|
|
520
|
+
|
|
521
|
+
/**
|
|
522
|
+
* Draw a a point at the specified coordinates
|
|
523
|
+
* @name fillPoint
|
|
524
|
+
* @memberof CanvasRenderer
|
|
525
|
+
* @param {number} x
|
|
526
|
+
* @param {number} y
|
|
527
|
+
* @param {number} width
|
|
528
|
+
* @param {number} height
|
|
529
|
+
*/
|
|
530
|
+
fillPoint(x, y) {
|
|
531
|
+
this.strokePoint(x, y);
|
|
532
|
+
}
|
|
533
|
+
|
|
507
534
|
/**
|
|
508
535
|
* return a reference to the font 2d Context
|
|
509
536
|
* @ignore
|