melonjs 9.1.0 → 10.0.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/{LICENSE → LICENSE.md} +0 -0
- package/README.md +93 -57
- package/dist/melonjs.js +10334 -11179
- package/dist/melonjs.min.js +4 -10
- package/dist/melonjs.module.d.ts +13206 -0
- package/dist/melonjs.module.js +9913 -10872
- package/package.json +19 -14
- package/src/audio/audio.js +477 -553
- package/src/camera/camera2d.js +67 -65
- package/src/entity/draggable.js +26 -35
- package/src/entity/droptarget.js +17 -14
- package/src/entity/entity.js +59 -79
- package/src/game.js +194 -204
- package/src/index.js +12 -30
- package/src/input/gamepad.js +8 -19
- package/src/input/keyboard.js +4 -4
- package/src/input/pointer.js +14 -12
- package/src/input/pointerevent.js +15 -13
- package/src/lang/deprecated.js +2 -887
- package/src/level/level.js +3 -3
- package/src/level/tiled/TMXGroup.js +7 -11
- package/src/level/tiled/TMXLayer.js +33 -32
- package/src/level/tiled/TMXTileMap.js +15 -19
- package/src/level/tiled/TMXTileset.js +5 -5
- package/src/level/tiled/TMXUtils.js +3 -3
- package/src/level/tiled/renderer/TMXRenderer.js +4 -0
- package/src/loader/loader.js +8 -23
- package/src/loader/loadingscreen.js +51 -60
- package/src/math/matrix3.js +1 -1
- package/src/particles/emitter.js +36 -39
- package/src/particles/particle.js +27 -12
- package/src/particles/particlecontainer.js +17 -16
- package/src/physics/body.js +80 -118
- package/src/physics/collision.js +5 -235
- package/src/physics/detector.js +235 -0
- package/src/physics/quadtree.js +14 -14
- package/src/physics/world.js +84 -18
- package/src/plugin/plugin.js +26 -24
- package/src/polyfill/console.js +9 -14
- package/src/renderable/GUI.js +48 -62
- package/src/renderable/collectable.js +11 -4
- package/src/renderable/colorlayer.js +28 -26
- package/src/renderable/container.js +120 -96
- package/src/renderable/imagelayer.js +94 -93
- package/src/renderable/renderable.js +164 -138
- package/src/renderable/sprite.js +42 -44
- package/src/renderable/trigger.js +24 -17
- package/src/shapes/ellipse.js +27 -27
- package/src/shapes/line.js +12 -8
- package/src/shapes/poly.js +77 -49
- package/src/shapes/rectangle.js +193 -268
- package/src/state/stage.js +23 -25
- package/src/state/state.js +35 -86
- package/src/system/device.js +233 -285
- package/src/system/event.js +485 -432
- package/src/system/pooling.js +61 -54
- package/src/system/save.js +17 -16
- package/src/system/timer.js +34 -38
- package/src/text/bitmaptext.js +44 -46
- package/src/text/text.js +39 -34
- package/src/tweens/easing.js +0 -2
- package/src/tweens/interpolation.js +3 -8
- package/src/tweens/tween.js +332 -351
- package/src/utils/function.js +6 -8
- package/src/utils/utils.js +34 -30
- package/src/video/canvas/canvas_renderer.js +13 -8
- package/src/video/renderer.js +8 -7
- package/src/video/texture.js +8 -8
- package/src/video/texture_cache.js +5 -5
- package/src/video/video.js +373 -403
- package/src/video/webgl/glshader.js +2 -2
- package/src/video/webgl/webgl_compositor.js +14 -8
- package/src/video/webgl/webgl_renderer.js +21 -19
- package/plugins/debug/debugPanel.js +0 -770
- package/plugins/debug/font/PressStart2P.fnt +0 -100
- package/plugins/debug/font/PressStart2P.ltr +0 -1
- package/plugins/debug/font/PressStart2P.png +0 -0
- package/plugins/debug/particleDebugPanel.js +0 -303
|
@@ -17,14 +17,15 @@ import { clamp } from "./../math/math.js";
|
|
|
17
17
|
* @param {Number} width object width
|
|
18
18
|
* @param {Number} height object height
|
|
19
19
|
*/
|
|
20
|
-
|
|
20
|
+
class Renderable extends Rect {
|
|
21
|
+
|
|
21
22
|
/**
|
|
22
23
|
* @ignore
|
|
23
24
|
*/
|
|
24
|
-
|
|
25
|
+
constructor(x, y, width, height) {
|
|
25
26
|
|
|
26
27
|
// parent constructor
|
|
27
|
-
|
|
28
|
+
super(x, y, width, height);
|
|
28
29
|
|
|
29
30
|
/**
|
|
30
31
|
* to identify the object as a renderable object
|
|
@@ -52,11 +53,11 @@ var Renderable = Rect.extend({
|
|
|
52
53
|
* @memberOf me.Renderable#
|
|
53
54
|
* @example
|
|
54
55
|
* // define a new Player Class
|
|
55
|
-
*
|
|
56
|
+
* class PlayerEntity extends me.Sprite {
|
|
56
57
|
* // constructor
|
|
57
|
-
*
|
|
58
|
+
* constructor(x, y, settings) {
|
|
58
59
|
* // call the parent constructor
|
|
59
|
-
*
|
|
60
|
+
* super(x, y , settings);
|
|
60
61
|
*
|
|
61
62
|
* // define a basic walking animation
|
|
62
63
|
* this.addAnimation("walk", [...]);
|
|
@@ -69,13 +70,14 @@ var Renderable = Rect.extend({
|
|
|
69
70
|
* this.body = new me.Body(this);
|
|
70
71
|
* // add a default collision shape
|
|
71
72
|
* this.body.addShape(new me.Rect(0, 0, this.width, this.height));
|
|
72
|
-
* // configure max speed and
|
|
73
|
+
* // configure max speed, friction, and initial force to be applied
|
|
73
74
|
* this.body.setMaxVelocity(3, 15);
|
|
74
75
|
* this.body.setFriction(0.4, 0);
|
|
76
|
+
* this.body.force.set(3, 0);
|
|
75
77
|
*
|
|
76
78
|
* // set the display to follow our position on both axis
|
|
77
79
|
* me.game.viewport.follow(this.pos, me.game.viewport.AXIS.BOTH);
|
|
78
|
-
* }
|
|
80
|
+
* }
|
|
79
81
|
*
|
|
80
82
|
* ...
|
|
81
83
|
*
|
|
@@ -310,12 +312,68 @@ var Renderable = Rect.extend({
|
|
|
310
312
|
|
|
311
313
|
// ensure it's fully opaque by default
|
|
312
314
|
this.setOpacity(1.0);
|
|
313
|
-
}
|
|
315
|
+
}
|
|
316
|
+
|
|
317
|
+
/**
|
|
318
|
+
* Whether the renderable object is visible and within the viewport
|
|
319
|
+
* @public
|
|
320
|
+
* @readonly
|
|
321
|
+
* @type Boolean
|
|
322
|
+
* @default false
|
|
323
|
+
* @name inViewport
|
|
324
|
+
* @memberOf me.Renderable
|
|
325
|
+
*/
|
|
326
|
+
|
|
327
|
+
/**
|
|
328
|
+
* @ignore
|
|
329
|
+
*/
|
|
330
|
+
get inViewport() {
|
|
331
|
+
return this._inViewport;
|
|
332
|
+
}
|
|
333
|
+
|
|
334
|
+
/**
|
|
335
|
+
* @ignore
|
|
336
|
+
*/
|
|
337
|
+
set inViewport(value) {
|
|
338
|
+
if (this._inViewport !== value) {
|
|
339
|
+
this._inViewport = value;
|
|
340
|
+
if (typeof this.onVisibilityChange === "function") {
|
|
341
|
+
this.onVisibilityChange.call(this, value);
|
|
342
|
+
}
|
|
343
|
+
}
|
|
344
|
+
}
|
|
345
|
+
|
|
346
|
+
/**
|
|
347
|
+
* returns true if this renderable is flipped on the horizontal axis
|
|
348
|
+
* @public
|
|
349
|
+
* @see me.Renderable#flipX
|
|
350
|
+
* @type {Boolean}
|
|
351
|
+
* @name isFlippedX
|
|
352
|
+
* @memberOf me.Renderable
|
|
353
|
+
*/
|
|
354
|
+
|
|
355
|
+
/**
|
|
356
|
+
* @ignore
|
|
357
|
+
*/
|
|
358
|
+
get isFlippedX() {
|
|
359
|
+
return this._flip.x === true;
|
|
360
|
+
}
|
|
314
361
|
|
|
315
|
-
/**
|
|
316
|
-
|
|
317
|
-
|
|
318
|
-
|
|
362
|
+
/**
|
|
363
|
+
* returns true if this renderable is flipped on the vertical axis
|
|
364
|
+
* @public
|
|
365
|
+
* @see me.Renderable#flipY
|
|
366
|
+
* @type {Boolean}
|
|
367
|
+
* @name isFlippedY
|
|
368
|
+
* @memberOf me.Renderable
|
|
369
|
+
*/
|
|
370
|
+
|
|
371
|
+
/**
|
|
372
|
+
* @ignore
|
|
373
|
+
*/
|
|
374
|
+
get isFlippedY() {
|
|
375
|
+
return this._flip.y === true;
|
|
376
|
+
}
|
|
319
377
|
|
|
320
378
|
/**
|
|
321
379
|
* returns the bounding box for this renderable
|
|
@@ -324,9 +382,9 @@ var Renderable = Rect.extend({
|
|
|
324
382
|
* @function
|
|
325
383
|
* @return {me.Bounds} bounding box Rectangle object
|
|
326
384
|
*/
|
|
327
|
-
getBounds
|
|
385
|
+
getBounds() {
|
|
328
386
|
if (typeof this._bounds === "undefined") {
|
|
329
|
-
|
|
387
|
+
super.getBounds();
|
|
330
388
|
if (this.isFinite()) {
|
|
331
389
|
this._bounds.setMinMax(this.pos.x, this.pos.y, this.pos.x + this.width, this.pos.y + this.height);
|
|
332
390
|
} else {
|
|
@@ -336,7 +394,7 @@ var Renderable = Rect.extend({
|
|
|
336
394
|
|
|
337
395
|
}
|
|
338
396
|
return this._bounds;
|
|
339
|
-
}
|
|
397
|
+
}
|
|
340
398
|
|
|
341
399
|
/**
|
|
342
400
|
* get the renderable alpha channel value<br>
|
|
@@ -345,9 +403,9 @@ var Renderable = Rect.extend({
|
|
|
345
403
|
* @function
|
|
346
404
|
* @return {Number} current opacity value between 0 and 1
|
|
347
405
|
*/
|
|
348
|
-
getOpacity
|
|
406
|
+
getOpacity() {
|
|
349
407
|
return this.alpha;
|
|
350
|
-
}
|
|
408
|
+
}
|
|
351
409
|
|
|
352
410
|
/**
|
|
353
411
|
* set the renderable alpha channel value<br>
|
|
@@ -356,7 +414,7 @@ var Renderable = Rect.extend({
|
|
|
356
414
|
* @function
|
|
357
415
|
* @param {Number} alpha opacity value between 0.0 and 1.0
|
|
358
416
|
*/
|
|
359
|
-
setOpacity
|
|
417
|
+
setOpacity(alpha) {
|
|
360
418
|
if (typeof (alpha) === "number") {
|
|
361
419
|
this.alpha = clamp(alpha, 0.0, 1.0);
|
|
362
420
|
// Set to 1 if alpha is NaN
|
|
@@ -364,7 +422,7 @@ var Renderable = Rect.extend({
|
|
|
364
422
|
this.alpha = 1.0;
|
|
365
423
|
}
|
|
366
424
|
}
|
|
367
|
-
}
|
|
425
|
+
}
|
|
368
426
|
|
|
369
427
|
/**
|
|
370
428
|
* flip the renderable on the horizontal axis (around the center of the renderable)
|
|
@@ -372,14 +430,14 @@ var Renderable = Rect.extend({
|
|
|
372
430
|
* @name flipX
|
|
373
431
|
* @memberOf me.Renderable.prototype
|
|
374
432
|
* @function
|
|
375
|
-
* @param {Boolean} [flip=
|
|
433
|
+
* @param {Boolean} [flip=true] `true` to flip this renderable.
|
|
376
434
|
* @return {me.Renderable} Reference to this object for method chaining
|
|
377
435
|
*/
|
|
378
|
-
flipX
|
|
436
|
+
flipX(flip = true) {
|
|
379
437
|
this._flip.x = !!flip;
|
|
380
438
|
this.isDirty = true;
|
|
381
439
|
return this;
|
|
382
|
-
}
|
|
440
|
+
}
|
|
383
441
|
|
|
384
442
|
/**
|
|
385
443
|
* flip the renderable on the vertical axis (around the center of the renderable)
|
|
@@ -387,14 +445,14 @@ var Renderable = Rect.extend({
|
|
|
387
445
|
* @name flipY
|
|
388
446
|
* @memberOf me.Renderable.prototype
|
|
389
447
|
* @function
|
|
390
|
-
* @param {Boolean} [flip=
|
|
448
|
+
* @param {Boolean} [flip=true] `true` to flip this renderable.
|
|
391
449
|
* @return {me.Renderable} Reference to this object for method chaining
|
|
392
450
|
*/
|
|
393
|
-
flipY
|
|
451
|
+
flipY(flip = true) {
|
|
394
452
|
this._flip.y = !!flip;
|
|
395
453
|
this.isDirty = true;
|
|
396
454
|
return this;
|
|
397
|
-
}
|
|
455
|
+
}
|
|
398
456
|
|
|
399
457
|
/**
|
|
400
458
|
* multiply the renderable currentTransform with the given matrix
|
|
@@ -405,13 +463,13 @@ var Renderable = Rect.extend({
|
|
|
405
463
|
* @param {me.Matrix2d} matrix the transformation matrix
|
|
406
464
|
* @return {me.Renderable} Reference to this object for method chaining
|
|
407
465
|
*/
|
|
408
|
-
transform
|
|
466
|
+
transform(m) {
|
|
409
467
|
this.currentTransform.multiply(m);
|
|
410
|
-
//
|
|
468
|
+
//super.transform(m);
|
|
411
469
|
this.updateBoundsPos(this.pos.x, this.pos.y);
|
|
412
470
|
this.isDirty = true;
|
|
413
471
|
return this;
|
|
414
|
-
}
|
|
472
|
+
}
|
|
415
473
|
|
|
416
474
|
/**
|
|
417
475
|
* return the angle to the specified target
|
|
@@ -421,7 +479,7 @@ var Renderable = Rect.extend({
|
|
|
421
479
|
* @param {me.Renderable|me.Vector2d|me.Vector3d} target
|
|
422
480
|
* @return {Number} angle in radians
|
|
423
481
|
*/
|
|
424
|
-
angleTo
|
|
482
|
+
angleTo(target) {
|
|
425
483
|
var a = this.getBounds();
|
|
426
484
|
var ax, ay;
|
|
427
485
|
|
|
@@ -435,7 +493,7 @@ var Renderable = Rect.extend({
|
|
|
435
493
|
}
|
|
436
494
|
|
|
437
495
|
return Math.atan2(ay, ax);
|
|
438
|
-
}
|
|
496
|
+
}
|
|
439
497
|
|
|
440
498
|
/**
|
|
441
499
|
* return the distance to the specified target
|
|
@@ -445,7 +503,7 @@ var Renderable = Rect.extend({
|
|
|
445
503
|
* @param {me.Renderable|me.Vector2d|me.Vector3d} target
|
|
446
504
|
* @return {Number} distance
|
|
447
505
|
*/
|
|
448
|
-
distanceTo
|
|
506
|
+
distanceTo(target) {
|
|
449
507
|
var a = this.getBounds();
|
|
450
508
|
var dx, dy;
|
|
451
509
|
|
|
@@ -459,7 +517,7 @@ var Renderable = Rect.extend({
|
|
|
459
517
|
}
|
|
460
518
|
|
|
461
519
|
return Math.sqrt(dx * dx + dy * dy);
|
|
462
|
-
}
|
|
520
|
+
}
|
|
463
521
|
|
|
464
522
|
/**
|
|
465
523
|
* Rotate this renderable towards the given target.
|
|
@@ -469,7 +527,7 @@ var Renderable = Rect.extend({
|
|
|
469
527
|
* @param {me.Renderable|me.Vector2d|me.Vector3d} target the renderable or position to look at
|
|
470
528
|
* @return {me.Renderable} Reference to this object for method chaining
|
|
471
529
|
*/
|
|
472
|
-
lookAt
|
|
530
|
+
lookAt(target) {
|
|
473
531
|
var position;
|
|
474
532
|
|
|
475
533
|
if (target instanceof Renderable) {
|
|
@@ -483,7 +541,7 @@ var Renderable = Rect.extend({
|
|
|
483
541
|
this.rotate(angle);
|
|
484
542
|
|
|
485
543
|
return this;
|
|
486
|
-
}
|
|
544
|
+
}
|
|
487
545
|
|
|
488
546
|
/**
|
|
489
547
|
* Rotate this renderable by the specified angle (in radians).
|
|
@@ -494,14 +552,14 @@ var Renderable = Rect.extend({
|
|
|
494
552
|
* @param {me.Vector2d|me.ObservableVector2d} [v] an optional point to rotate around
|
|
495
553
|
* @return {me.Renderable} Reference to this object for method chaining
|
|
496
554
|
*/
|
|
497
|
-
rotate
|
|
555
|
+
rotate(angle) {
|
|
498
556
|
if (!isNaN(angle)) {
|
|
499
557
|
this.currentTransform.rotate(angle);
|
|
500
558
|
//this.updateBoundsPos(this.pos.x, this.pos.y);
|
|
501
559
|
this.isDirty = true;
|
|
502
560
|
}
|
|
503
561
|
return this;
|
|
504
|
-
}
|
|
562
|
+
}
|
|
505
563
|
|
|
506
564
|
/**
|
|
507
565
|
* scale the renderable around his anchor point. Scaling actually applies changes
|
|
@@ -516,12 +574,12 @@ var Renderable = Rect.extend({
|
|
|
516
574
|
* @param {Number} [y=x] a number representing the ordinate of the scaling vector.
|
|
517
575
|
* @return {me.Renderable} Reference to this object for method chaining
|
|
518
576
|
*/
|
|
519
|
-
scale
|
|
577
|
+
scale(x, y) {
|
|
520
578
|
this.currentTransform.scale(x, y);
|
|
521
|
-
|
|
579
|
+
super.scale(x, y);
|
|
522
580
|
this.isDirty = true;
|
|
523
581
|
return this;
|
|
524
|
-
}
|
|
582
|
+
}
|
|
525
583
|
|
|
526
584
|
/**
|
|
527
585
|
* scale the renderable around his anchor point
|
|
@@ -531,10 +589,10 @@ var Renderable = Rect.extend({
|
|
|
531
589
|
* @param {me.Vector2d} vector scaling vector
|
|
532
590
|
* @return {me.Renderable} Reference to this object for method chaining
|
|
533
591
|
*/
|
|
534
|
-
scaleV
|
|
592
|
+
scaleV(v) {
|
|
535
593
|
this.scale(v.x, v.y);
|
|
536
594
|
return this;
|
|
537
|
-
}
|
|
595
|
+
}
|
|
538
596
|
|
|
539
597
|
/**
|
|
540
598
|
* update function. <br>
|
|
@@ -546,9 +604,9 @@ var Renderable = Rect.extend({
|
|
|
546
604
|
* @param {Number} dt time since the last update in milliseconds.
|
|
547
605
|
* @return false
|
|
548
606
|
**/
|
|
549
|
-
update
|
|
607
|
+
update(/* dt */) {
|
|
550
608
|
return this.isDirty;
|
|
551
|
-
}
|
|
609
|
+
}
|
|
552
610
|
|
|
553
611
|
/**
|
|
554
612
|
* update the bounding box for this shape.
|
|
@@ -558,11 +616,11 @@ var Renderable = Rect.extend({
|
|
|
558
616
|
* @function
|
|
559
617
|
* @return {me.Bounds} this shape bounding box Rectangle object
|
|
560
618
|
*/
|
|
561
|
-
updateBounds
|
|
562
|
-
|
|
619
|
+
updateBounds() {
|
|
620
|
+
super.updateBounds();
|
|
563
621
|
this.updateBoundsPos(this.pos.x, this.pos.y);
|
|
564
622
|
return this.getBounds();
|
|
565
|
-
}
|
|
623
|
+
}
|
|
566
624
|
|
|
567
625
|
/**
|
|
568
626
|
* update the renderable's bounding rect (private)
|
|
@@ -571,7 +629,7 @@ var Renderable = Rect.extend({
|
|
|
571
629
|
* @memberOf me.Renderable.prototype
|
|
572
630
|
* @function
|
|
573
631
|
*/
|
|
574
|
-
updateBoundsPos
|
|
632
|
+
updateBoundsPos(newX, newY) {
|
|
575
633
|
var bounds = this.getBounds();
|
|
576
634
|
|
|
577
635
|
bounds.shift(newX, newY);
|
|
@@ -595,7 +653,7 @@ var Renderable = Rect.extend({
|
|
|
595
653
|
bounds.translate(this.ancestor.getAbsolutePosition());
|
|
596
654
|
}
|
|
597
655
|
//return bounds;
|
|
598
|
-
}
|
|
656
|
+
}
|
|
599
657
|
|
|
600
658
|
/**
|
|
601
659
|
* return the renderable absolute position in the game world
|
|
@@ -604,7 +662,7 @@ var Renderable = Rect.extend({
|
|
|
604
662
|
* @function
|
|
605
663
|
* @return {me.Vector2d}
|
|
606
664
|
*/
|
|
607
|
-
getAbsolutePosition
|
|
665
|
+
getAbsolutePosition() {
|
|
608
666
|
if (typeof this._absPos === "undefined") {
|
|
609
667
|
this._absPos = pool.pull("Vector2d");
|
|
610
668
|
}
|
|
@@ -614,7 +672,7 @@ var Renderable = Rect.extend({
|
|
|
614
672
|
this._absPos.add(this.ancestor.getAbsolutePosition());
|
|
615
673
|
}
|
|
616
674
|
return this._absPos;
|
|
617
|
-
}
|
|
675
|
+
}
|
|
618
676
|
|
|
619
677
|
/**
|
|
620
678
|
* called when the anchor point value is changed
|
|
@@ -623,13 +681,13 @@ var Renderable = Rect.extend({
|
|
|
623
681
|
* @memberOf me.Renderable.prototype
|
|
624
682
|
* @function
|
|
625
683
|
*/
|
|
626
|
-
onAnchorUpdate
|
|
684
|
+
onAnchorUpdate(newX, newY) {
|
|
627
685
|
// since the callback is called before setting the new value
|
|
628
686
|
// manually update the anchor point (required for updateBoundsPos)
|
|
629
687
|
this.anchorPoint.setMuted(newX, newY);
|
|
630
|
-
// then call
|
|
688
|
+
// then call updateBounds
|
|
631
689
|
this.updateBoundsPos(this.pos.x, this.pos.y);
|
|
632
|
-
}
|
|
690
|
+
}
|
|
633
691
|
|
|
634
692
|
|
|
635
693
|
/**
|
|
@@ -642,13 +700,14 @@ var Renderable = Rect.extend({
|
|
|
642
700
|
* @protected
|
|
643
701
|
* @param {me.CanvasRenderer|me.WebGLRenderer} renderer a renderer object
|
|
644
702
|
**/
|
|
645
|
-
preDraw
|
|
703
|
+
preDraw(renderer) {
|
|
646
704
|
var bounds = this.getBounds();
|
|
647
705
|
var ax = bounds.width * this.anchorPoint.x,
|
|
648
706
|
ay = bounds.height * this.anchorPoint.y;
|
|
649
707
|
|
|
650
|
-
// save context
|
|
708
|
+
// save renderer context
|
|
651
709
|
renderer.save();
|
|
710
|
+
|
|
652
711
|
// apply the defined alpha value
|
|
653
712
|
renderer.setGlobalAlpha(renderer.globalAlpha() * this.getOpacity());
|
|
654
713
|
|
|
@@ -662,6 +721,13 @@ var Renderable = Rect.extend({
|
|
|
662
721
|
renderer.translate(-dx, -dy);
|
|
663
722
|
}
|
|
664
723
|
|
|
724
|
+
// apply stencil mask if defined
|
|
725
|
+
if (typeof this.mask !== "undefined") {
|
|
726
|
+
renderer.translate(this.pos.x, this.pos.y);
|
|
727
|
+
renderer.setMask(this.mask);
|
|
728
|
+
renderer.translate(-this.pos.x, -this.pos.y);
|
|
729
|
+
}
|
|
730
|
+
|
|
665
731
|
if ((this.autoTransform === true) && (!this.currentTransform.isIdentity())) {
|
|
666
732
|
// apply the renderable transformation matrix
|
|
667
733
|
renderer.translate(this.pos.x, this.pos.y);
|
|
@@ -672,14 +738,9 @@ var Renderable = Rect.extend({
|
|
|
672
738
|
// offset by the anchor point
|
|
673
739
|
renderer.translate(-ax, -ay);
|
|
674
740
|
|
|
675
|
-
|
|
676
|
-
if (typeof this.mask !== "undefined") {
|
|
677
|
-
renderer.setMask(this.mask);
|
|
678
|
-
}
|
|
679
|
-
|
|
680
741
|
// apply the defined tint, if any
|
|
681
742
|
renderer.setTint(this.tint);
|
|
682
|
-
}
|
|
743
|
+
}
|
|
683
744
|
|
|
684
745
|
/**
|
|
685
746
|
* object draw. <br>
|
|
@@ -690,9 +751,9 @@ var Renderable = Rect.extend({
|
|
|
690
751
|
* @protected
|
|
691
752
|
* @param {me.CanvasRenderer|me.WebGLRenderer} renderer a renderer object
|
|
692
753
|
**/
|
|
693
|
-
draw
|
|
754
|
+
draw(/*renderer*/) {
|
|
694
755
|
// empty one !
|
|
695
|
-
}
|
|
756
|
+
}
|
|
696
757
|
|
|
697
758
|
/**
|
|
698
759
|
* restore the rendering context after drawing. <br>
|
|
@@ -703,26 +764,55 @@ var Renderable = Rect.extend({
|
|
|
703
764
|
* @protected
|
|
704
765
|
* @param {me.CanvasRenderer|me.WebGLRenderer} renderer a renderer object
|
|
705
766
|
**/
|
|
706
|
-
postDraw
|
|
767
|
+
postDraw(renderer) {
|
|
768
|
+
|
|
769
|
+
// remove the previously applied tint
|
|
770
|
+
renderer.clearTint();
|
|
771
|
+
|
|
772
|
+
// clear the mask if set
|
|
707
773
|
if (typeof this.mask !== "undefined") {
|
|
708
774
|
renderer.clearMask();
|
|
709
775
|
}
|
|
710
776
|
|
|
711
|
-
//
|
|
712
|
-
renderer.
|
|
777
|
+
// restore the context
|
|
778
|
+
renderer.restore();
|
|
713
779
|
|
|
714
780
|
// reset the dirty flag
|
|
715
781
|
this.isDirty = false;
|
|
782
|
+
}
|
|
716
783
|
|
|
717
|
-
|
|
718
|
-
|
|
719
|
-
|
|
784
|
+
/**
|
|
785
|
+
* onCollision callback, triggered in case of collision,
|
|
786
|
+
* when this renderable body is colliding with another one
|
|
787
|
+
* @name onCollision
|
|
788
|
+
* @memberOf me.Renderable.prototype
|
|
789
|
+
* @function
|
|
790
|
+
* @param {me.collision.ResponseObject} response the collision response object
|
|
791
|
+
* @param {me.Renderable} other the other renderable touching this one (a reference to response.a or response.b)
|
|
792
|
+
* @return {Boolean} true if the object should respond to the collision (its position and velocity will be corrected)
|
|
793
|
+
* @example
|
|
794
|
+
* // colision handler
|
|
795
|
+
* onCollision(response) {
|
|
796
|
+
* if (response.b.body.collisionType === me.collision.types.ENEMY_OBJECT) {
|
|
797
|
+
* // makes the other object solid, by substracting the overlap vector to the current position
|
|
798
|
+
* this.pos.sub(response.overlapV);
|
|
799
|
+
* this.hurt();
|
|
800
|
+
* // not solid
|
|
801
|
+
* return false;
|
|
802
|
+
* }
|
|
803
|
+
* // Make the object solid
|
|
804
|
+
* return true;
|
|
805
|
+
* },
|
|
806
|
+
*/
|
|
807
|
+
onCollision() {
|
|
808
|
+
return false;
|
|
809
|
+
}
|
|
720
810
|
|
|
721
811
|
/**
|
|
722
812
|
* Destroy function<br>
|
|
723
813
|
* @ignore
|
|
724
814
|
*/
|
|
725
|
-
destroy
|
|
815
|
+
destroy() {
|
|
726
816
|
// allow recycling object properties
|
|
727
817
|
pool.push(this.currentTransform);
|
|
728
818
|
this.currentTransform = undefined;
|
|
@@ -766,7 +856,7 @@ var Renderable = Rect.extend({
|
|
|
766
856
|
|
|
767
857
|
// call the user defined destroy method
|
|
768
858
|
this.onDestroyEvent.apply(this, arguments);
|
|
769
|
-
}
|
|
859
|
+
}
|
|
770
860
|
|
|
771
861
|
/**
|
|
772
862
|
* OnDestroy Notification function<br>
|
|
@@ -775,75 +865,11 @@ var Renderable = Rect.extend({
|
|
|
775
865
|
* @memberOf me.Renderable
|
|
776
866
|
* @function
|
|
777
867
|
*/
|
|
778
|
-
onDestroyEvent
|
|
868
|
+
onDestroyEvent() {
|
|
779
869
|
// to be extended !
|
|
780
870
|
}
|
|
781
|
-
});
|
|
782
871
|
|
|
783
|
-
|
|
784
|
-
* Whether the renderable object is visible and within the viewport
|
|
785
|
-
* @public
|
|
786
|
-
* @readonly
|
|
787
|
-
* @type Boolean
|
|
788
|
-
* @default false
|
|
789
|
-
* @name inViewport
|
|
790
|
-
* @memberOf me.Renderable
|
|
791
|
-
*/
|
|
792
|
-
Object.defineProperty(Renderable.prototype, "inViewport", {
|
|
793
|
-
/**
|
|
794
|
-
* @ignore
|
|
795
|
-
*/
|
|
796
|
-
get : function () {
|
|
797
|
-
return this._inViewport;
|
|
798
|
-
},
|
|
799
|
-
/**
|
|
800
|
-
* @ignore
|
|
801
|
-
*/
|
|
802
|
-
set : function (value) {
|
|
803
|
-
if (this._inViewport !== value) {
|
|
804
|
-
this._inViewport = value;
|
|
805
|
-
if (typeof this.onVisibilityChange === "function") {
|
|
806
|
-
this.onVisibilityChange.call(this, value);
|
|
807
|
-
}
|
|
808
|
-
}
|
|
809
|
-
},
|
|
810
|
-
configurable : true
|
|
811
|
-
});
|
|
812
|
-
|
|
813
|
-
/**
|
|
814
|
-
* returns true if this renderable is flipped on the horizontal axis
|
|
815
|
-
* @public
|
|
816
|
-
* @see me.Renderable#flipX
|
|
817
|
-
* @type {Boolean}
|
|
818
|
-
* @name isFlippedX
|
|
819
|
-
* @memberOf me.Renderable
|
|
820
|
-
*/
|
|
821
|
-
Object.defineProperty(Renderable.prototype, "isFlippedX", {
|
|
822
|
-
/**
|
|
823
|
-
* @ignore
|
|
824
|
-
*/
|
|
825
|
-
get : function () {
|
|
826
|
-
return this._flip.x === true;
|
|
827
|
-
},
|
|
828
|
-
configurable : true
|
|
829
|
-
});
|
|
872
|
+
};
|
|
830
873
|
|
|
831
|
-
/**
|
|
832
|
-
* returns true if this renderable is flipped on the vertical axis
|
|
833
|
-
* @public
|
|
834
|
-
* @see me.Renderable#flipY
|
|
835
|
-
* @type {Boolean}
|
|
836
|
-
* @name isFlippedY
|
|
837
|
-
* @memberOf me.Renderable
|
|
838
|
-
*/
|
|
839
|
-
Object.defineProperty(Renderable.prototype, "isFlippedY", {
|
|
840
|
-
/**
|
|
841
|
-
* @ignore
|
|
842
|
-
*/
|
|
843
|
-
get : function () {
|
|
844
|
-
return this._flip.y === true;
|
|
845
|
-
},
|
|
846
|
-
configurable : true
|
|
847
|
-
});
|
|
848
874
|
|
|
849
875
|
export default Renderable;
|