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
package/src/renderable/sprite.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import Vector2d from "./../math/vector2.js";
|
|
2
|
-
import
|
|
2
|
+
import { renderer } from "./../video/video.js";
|
|
3
3
|
import pool from "./../system/pooling.js";
|
|
4
4
|
import loader from "./../loader/loader.js";
|
|
5
5
|
import {Texture } from "./../video/texture.js";
|
|
@@ -7,6 +7,7 @@ import Renderable from "./renderable.js";
|
|
|
7
7
|
|
|
8
8
|
|
|
9
9
|
/**
|
|
10
|
+
* @classdesc
|
|
10
11
|
* An object to display a fixed or animated sprite on screen.
|
|
11
12
|
* @class
|
|
12
13
|
* @extends me.Renderable
|
|
@@ -43,11 +44,16 @@ import Renderable from "./renderable.js";
|
|
|
43
44
|
* region : "npc2.png",
|
|
44
45
|
* });
|
|
45
46
|
*/
|
|
46
|
-
|
|
47
|
+
|
|
48
|
+
class Sprite extends Renderable {
|
|
49
|
+
|
|
47
50
|
/**
|
|
48
51
|
* @ignore
|
|
49
52
|
*/
|
|
50
|
-
|
|
53
|
+
constructor(x, y, settings) {
|
|
54
|
+
|
|
55
|
+
// call the super constructor
|
|
56
|
+
super(x, y, 0, 0);
|
|
51
57
|
|
|
52
58
|
/**
|
|
53
59
|
* pause and resume animation
|
|
@@ -121,9 +127,6 @@ var Sprite = Renderable.extend({
|
|
|
121
127
|
state : false
|
|
122
128
|
};
|
|
123
129
|
|
|
124
|
-
// call the super constructor
|
|
125
|
-
this._super(Renderable, "init", [ x, y, 0, 0 ]);
|
|
126
|
-
|
|
127
130
|
// set the proper image/texture to use
|
|
128
131
|
if (settings.image instanceof Texture) {
|
|
129
132
|
this.source = settings.image;
|
|
@@ -147,22 +150,17 @@ var Sprite = Renderable.extend({
|
|
|
147
150
|
} else {
|
|
148
151
|
// HTMLImageElement/Canvas or String
|
|
149
152
|
this.image = (typeof settings.image === "object") ? settings.image : loader.getImage(settings.image);
|
|
153
|
+
// throw an error if image ends up being null/undefined
|
|
154
|
+
if (!this.image) {
|
|
155
|
+
throw new Error("me.Sprite: '" + settings.image + "' image/texture not found!");
|
|
156
|
+
}
|
|
150
157
|
// update the default "current" frame size
|
|
151
158
|
this.current.width = settings.framewidth = settings.framewidth || this.image.width;
|
|
152
159
|
this.current.height = settings.frameheight = settings.frameheight || this.image.height;
|
|
153
|
-
this.source =
|
|
160
|
+
this.source = renderer.cache.get(this.image, settings);
|
|
154
161
|
this.textureAtlas = this.source.getAtlas();
|
|
155
162
|
}
|
|
156
163
|
|
|
157
|
-
// throw an error if image ends up being null/undefined
|
|
158
|
-
if (!this.image) {
|
|
159
|
-
throw new Error((
|
|
160
|
-
(typeof(settings.image) === "string") ?
|
|
161
|
-
"'" + settings.image + "'" :
|
|
162
|
-
"Image"
|
|
163
|
-
) + " file for Image Layer '" + this.name + "' not found!");
|
|
164
|
-
}
|
|
165
|
-
|
|
166
164
|
// store/reset the current atlas information if specified
|
|
167
165
|
if (typeof(settings.atlas) !== "undefined") {
|
|
168
166
|
this.textureAtlas = settings.atlas;
|
|
@@ -214,7 +212,7 @@ var Sprite = Renderable.extend({
|
|
|
214
212
|
|
|
215
213
|
// enable currentTransform for me.Sprite based objects
|
|
216
214
|
this.autoTransform = true;
|
|
217
|
-
}
|
|
215
|
+
}
|
|
218
216
|
|
|
219
217
|
/**
|
|
220
218
|
* return the flickering state of the object
|
|
@@ -223,9 +221,9 @@ var Sprite = Renderable.extend({
|
|
|
223
221
|
* @function
|
|
224
222
|
* @return {Boolean}
|
|
225
223
|
*/
|
|
226
|
-
isFlickering
|
|
224
|
+
isFlickering() {
|
|
227
225
|
return this._flicker.isFlickering;
|
|
228
|
-
}
|
|
226
|
+
}
|
|
229
227
|
|
|
230
228
|
/**
|
|
231
229
|
* make the object flicker
|
|
@@ -242,7 +240,7 @@ var Sprite = Renderable.extend({
|
|
|
242
240
|
* me.game.world.removeChild(this);
|
|
243
241
|
* });
|
|
244
242
|
*/
|
|
245
|
-
flicker
|
|
243
|
+
flicker(duration, callback) {
|
|
246
244
|
this._flicker.duration = duration;
|
|
247
245
|
if (this._flicker.duration <= 0) {
|
|
248
246
|
this._flicker.isFlickering = false;
|
|
@@ -253,7 +251,7 @@ var Sprite = Renderable.extend({
|
|
|
253
251
|
this._flicker.isFlickering = true;
|
|
254
252
|
}
|
|
255
253
|
return this;
|
|
256
|
-
}
|
|
254
|
+
}
|
|
257
255
|
|
|
258
256
|
/**
|
|
259
257
|
* add an animation <br>
|
|
@@ -289,7 +287,7 @@ var Sprite = Renderable.extend({
|
|
|
289
287
|
* // set the standing animation as default
|
|
290
288
|
* this.setCurrentAnimation("stand");
|
|
291
289
|
*/
|
|
292
|
-
addAnimation
|
|
290
|
+
addAnimation(name, index, animationspeed) {
|
|
293
291
|
this.anim[name] = {
|
|
294
292
|
name : name,
|
|
295
293
|
frames : [],
|
|
@@ -355,7 +353,7 @@ var Sprite = Renderable.extend({
|
|
|
355
353
|
this.anim[name].length = counter;
|
|
356
354
|
|
|
357
355
|
return counter;
|
|
358
|
-
}
|
|
356
|
+
}
|
|
359
357
|
|
|
360
358
|
/**
|
|
361
359
|
* set the current animation
|
|
@@ -396,7 +394,7 @@ var Sprite = Renderable.extend({
|
|
|
396
394
|
* return false; // do not reset to first frame
|
|
397
395
|
* }).bind(this));
|
|
398
396
|
**/
|
|
399
|
-
setCurrentAnimation
|
|
397
|
+
setCurrentAnimation(name, resetAnim, _preserve_dt) {
|
|
400
398
|
if (this.anim[name]) {
|
|
401
399
|
this.current.name = name;
|
|
402
400
|
this.current.length = this.anim[this.current.name].length;
|
|
@@ -416,7 +414,7 @@ var Sprite = Renderable.extend({
|
|
|
416
414
|
throw new Error("animation id '" + name + "' not defined");
|
|
417
415
|
}
|
|
418
416
|
return this;
|
|
419
|
-
}
|
|
417
|
+
}
|
|
420
418
|
|
|
421
419
|
/**
|
|
422
420
|
* reverse the given or current animation if none is specified
|
|
@@ -427,7 +425,7 @@ var Sprite = Renderable.extend({
|
|
|
427
425
|
* @return {me.Sprite} Reference to this object for method chaining
|
|
428
426
|
* @see me.Sprite#animationspeed
|
|
429
427
|
*/
|
|
430
|
-
reverseAnimation
|
|
428
|
+
reverseAnimation(name) {
|
|
431
429
|
if (typeof name !== "undefined" && typeof this.anim[name] !== "undefined") {
|
|
432
430
|
this.anim[name].frames.reverse();
|
|
433
431
|
} else {
|
|
@@ -435,7 +433,7 @@ var Sprite = Renderable.extend({
|
|
|
435
433
|
}
|
|
436
434
|
this.isDirty = true;
|
|
437
435
|
return this;
|
|
438
|
-
}
|
|
436
|
+
}
|
|
439
437
|
|
|
440
438
|
/**
|
|
441
439
|
* return true if the specified animation is the current one.
|
|
@@ -449,9 +447,9 @@ var Sprite = Renderable.extend({
|
|
|
449
447
|
* // do something funny...
|
|
450
448
|
* }
|
|
451
449
|
*/
|
|
452
|
-
isCurrentAnimation
|
|
450
|
+
isCurrentAnimation(name) {
|
|
453
451
|
return this.current.name === name;
|
|
454
|
-
}
|
|
452
|
+
}
|
|
455
453
|
|
|
456
454
|
/**
|
|
457
455
|
* change the current texture atlas region for this sprite
|
|
@@ -465,7 +463,7 @@ var Sprite = Renderable.extend({
|
|
|
465
463
|
* // change the sprite to "shadedDark13.png";
|
|
466
464
|
* mySprite.setRegion(game.texture.getRegion("shadedDark13.png"));
|
|
467
465
|
*/
|
|
468
|
-
setRegion
|
|
466
|
+
setRegion(region) {
|
|
469
467
|
// set the source texture for the given region
|
|
470
468
|
this.image = this.source.getTexture(region);
|
|
471
469
|
// set the sprite offset within the texture
|
|
@@ -484,7 +482,7 @@ var Sprite = Renderable.extend({
|
|
|
484
482
|
}
|
|
485
483
|
this.isDirty = true;
|
|
486
484
|
return this;
|
|
487
|
-
}
|
|
485
|
+
}
|
|
488
486
|
|
|
489
487
|
/**
|
|
490
488
|
* force the current animation frame index.
|
|
@@ -497,10 +495,10 @@ var Sprite = Renderable.extend({
|
|
|
497
495
|
* // reset the current animation to the first frame
|
|
498
496
|
* this.setAnimationFrame();
|
|
499
497
|
*/
|
|
500
|
-
setAnimationFrame
|
|
498
|
+
setAnimationFrame(idx) {
|
|
501
499
|
this.current.idx = (idx || 0) % this.current.length;
|
|
502
500
|
return this.setRegion(this.getAnimationFrameObjectByIndex(this.current.idx));
|
|
503
|
-
}
|
|
501
|
+
}
|
|
504
502
|
|
|
505
503
|
/**
|
|
506
504
|
* return the current animation frame index.
|
|
@@ -509,9 +507,9 @@ var Sprite = Renderable.extend({
|
|
|
509
507
|
* @function
|
|
510
508
|
* @return {Number} current animation frame index
|
|
511
509
|
*/
|
|
512
|
-
getCurrentAnimationFrame
|
|
510
|
+
getCurrentAnimationFrame() {
|
|
513
511
|
return this.current.idx;
|
|
514
|
-
}
|
|
512
|
+
}
|
|
515
513
|
|
|
516
514
|
/**
|
|
517
515
|
* Returns the frame object by the index.
|
|
@@ -521,14 +519,14 @@ var Sprite = Renderable.extend({
|
|
|
521
519
|
* @private
|
|
522
520
|
* @return {Number} if using number indices. Returns {Object} containing frame data if using texture atlas
|
|
523
521
|
*/
|
|
524
|
-
getAnimationFrameObjectByIndex
|
|
522
|
+
getAnimationFrameObjectByIndex(id) {
|
|
525
523
|
return this.anim[this.current.name].frames[id];
|
|
526
|
-
}
|
|
524
|
+
}
|
|
527
525
|
|
|
528
526
|
/**
|
|
529
527
|
* @ignore
|
|
530
528
|
*/
|
|
531
|
-
update
|
|
529
|
+
update(dt) {
|
|
532
530
|
|
|
533
531
|
// Update animation if necessary
|
|
534
532
|
if (!this.animationpause && this.current && this.current.length > 0) {
|
|
@@ -586,22 +584,22 @@ var Sprite = Renderable.extend({
|
|
|
586
584
|
}
|
|
587
585
|
|
|
588
586
|
return this.isDirty;
|
|
589
|
-
}
|
|
587
|
+
}
|
|
590
588
|
|
|
591
589
|
/**
|
|
592
590
|
* Destroy function<br>
|
|
593
591
|
* @ignore
|
|
594
592
|
*/
|
|
595
|
-
destroy
|
|
593
|
+
destroy() {
|
|
596
594
|
pool.push(this.offset);
|
|
597
595
|
this.offset = undefined;
|
|
598
|
-
|
|
599
|
-
}
|
|
596
|
+
super.destroy();
|
|
597
|
+
}
|
|
600
598
|
|
|
601
599
|
/**
|
|
602
600
|
* @ignore
|
|
603
601
|
*/
|
|
604
|
-
draw
|
|
602
|
+
draw(renderer) {
|
|
605
603
|
// do nothing if we are flickering
|
|
606
604
|
if (this._flicker.isFlickering) {
|
|
607
605
|
this._flicker.state = !this._flicker.state;
|
|
@@ -643,6 +641,6 @@ var Sprite = Renderable.extend({
|
|
|
643
641
|
w, h // dw,dh
|
|
644
642
|
);
|
|
645
643
|
}
|
|
646
|
-
}
|
|
644
|
+
};
|
|
647
645
|
|
|
648
646
|
export default Sprite;
|
|
@@ -3,9 +3,10 @@ import collision from "./../physics/collision.js";
|
|
|
3
3
|
import Body from "./../physics/body.js";
|
|
4
4
|
import Rect from "./../shapes/rectangle.js";
|
|
5
5
|
import level from "./../level/level.js";
|
|
6
|
-
import
|
|
6
|
+
import { world, viewport } from "./../game.js";
|
|
7
7
|
|
|
8
8
|
/**
|
|
9
|
+
* classdesc
|
|
9
10
|
* trigger an event when colliding with another object
|
|
10
11
|
* @class
|
|
11
12
|
* @extends me.Renderable
|
|
@@ -34,12 +35,15 @@ import game from "./../game.js";
|
|
|
34
35
|
* }
|
|
35
36
|
* ));
|
|
36
37
|
*/
|
|
37
|
-
|
|
38
|
+
|
|
39
|
+
class Trigger extends Renderable {
|
|
40
|
+
|
|
38
41
|
/**
|
|
39
42
|
* @ignore
|
|
40
43
|
*/
|
|
41
|
-
|
|
42
|
-
|
|
44
|
+
constructor(x, y, settings) {
|
|
45
|
+
|
|
46
|
+
super(x, y, settings.width || 0, settings.height || 0);
|
|
43
47
|
|
|
44
48
|
// for backward compatibility
|
|
45
49
|
this.anchorPoint.set(0, 0);
|
|
@@ -72,28 +76,30 @@ var Trigger = Renderable.extend({
|
|
|
72
76
|
// physic body to check for collision against
|
|
73
77
|
this.body = new Body(this, settings.shapes || new Rect(0, 0, this.width, this.height));
|
|
74
78
|
this.body.collisionType = collision.types.ACTION_OBJECT;
|
|
79
|
+
// by default only collides with PLAYER_OBJECT
|
|
80
|
+
this.body.setCollisionMask(collision.types.PLAYER_OBJECT);
|
|
81
|
+
this.body.setStatic(true);
|
|
75
82
|
this.resize(this.body.getBounds().width, this.body.getBounds().height);
|
|
76
|
-
|
|
77
|
-
},
|
|
83
|
+
}
|
|
78
84
|
|
|
79
85
|
/**
|
|
80
86
|
* @ignore
|
|
81
87
|
*/
|
|
82
|
-
getTriggerSettings
|
|
88
|
+
getTriggerSettings() {
|
|
83
89
|
// Lookup for the container instance
|
|
84
90
|
if (typeof(this.triggerSettings.container) === "string") {
|
|
85
|
-
this.triggerSettings.container =
|
|
91
|
+
this.triggerSettings.container = world.getChildByName(this.triggerSettings.container)[0];
|
|
86
92
|
}
|
|
87
93
|
return this.triggerSettings;
|
|
88
|
-
}
|
|
94
|
+
}
|
|
89
95
|
|
|
90
96
|
/**
|
|
91
97
|
* @ignore
|
|
92
98
|
*/
|
|
93
|
-
onFadeComplete
|
|
99
|
+
onFadeComplete() {
|
|
94
100
|
level.load(this.gotolevel, this.getTriggerSettings());
|
|
95
|
-
|
|
96
|
-
}
|
|
101
|
+
viewport.fadeOut(this.fade, this.duration);
|
|
102
|
+
}
|
|
97
103
|
|
|
98
104
|
/**
|
|
99
105
|
* go to the specified level
|
|
@@ -103,7 +109,7 @@ var Trigger = Renderable.extend({
|
|
|
103
109
|
* @param {String} [level=this.nextlevel] name of the level to load
|
|
104
110
|
* @protected
|
|
105
111
|
*/
|
|
106
|
-
triggerEvent
|
|
112
|
+
triggerEvent() {
|
|
107
113
|
var triggerSettings = this.getTriggerSettings();
|
|
108
114
|
|
|
109
115
|
if (triggerSettings.event === "level") {
|
|
@@ -113,7 +119,7 @@ var Trigger = Renderable.extend({
|
|
|
113
119
|
if (this.fade && this.duration) {
|
|
114
120
|
if (!this.fading) {
|
|
115
121
|
this.fading = true;
|
|
116
|
-
|
|
122
|
+
viewport.fadeIn(this.fade, this.duration,
|
|
117
123
|
this.onFadeComplete.bind(this));
|
|
118
124
|
}
|
|
119
125
|
} else {
|
|
@@ -122,15 +128,16 @@ var Trigger = Renderable.extend({
|
|
|
122
128
|
} else {
|
|
123
129
|
throw new Error("Trigger invalid type");
|
|
124
130
|
}
|
|
125
|
-
}
|
|
131
|
+
}
|
|
126
132
|
|
|
127
133
|
/** @ignore */
|
|
128
|
-
onCollision
|
|
134
|
+
onCollision() {
|
|
129
135
|
if (this.name === "Trigger") {
|
|
130
136
|
this.triggerEvent.apply(this);
|
|
131
137
|
}
|
|
132
138
|
return false;
|
|
133
139
|
}
|
|
134
|
-
|
|
140
|
+
|
|
141
|
+
};
|
|
135
142
|
|
|
136
143
|
export default Trigger;
|
package/src/shapes/ellipse.js
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
import Vector2d from "./../math/vector2.js";
|
|
2
2
|
import pool from "./../system/pooling.js";
|
|
3
|
-
import "jay-extend";
|
|
4
3
|
|
|
5
4
|
/**
|
|
5
|
+
* @classdesc
|
|
6
6
|
* an ellipse Object
|
|
7
7
|
* @class
|
|
8
8
|
* @extends me.Object
|
|
@@ -13,11 +13,10 @@ import "jay-extend";
|
|
|
13
13
|
* @param {Number} w width (diameter) of the ellipse
|
|
14
14
|
* @param {Number} h height (diameter) of the ellipse
|
|
15
15
|
*/
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
init : function (x, y, w, h) {
|
|
16
|
+
|
|
17
|
+
class Ellipse {
|
|
18
|
+
|
|
19
|
+
constructor(x, y, w, h) {
|
|
21
20
|
/**
|
|
22
21
|
* the center coordinates of the ellipse
|
|
23
22
|
* @public
|
|
@@ -75,12 +74,12 @@ var Ellipse = window.Jay.extend({
|
|
|
75
74
|
// the shape type
|
|
76
75
|
this.shapeType = "Ellipse";
|
|
77
76
|
this.setShape(x, y, w, h);
|
|
78
|
-
}
|
|
77
|
+
}
|
|
79
78
|
|
|
80
79
|
/** @ignore */
|
|
81
|
-
onResetEvent
|
|
80
|
+
onResetEvent(x, y, w, h) {
|
|
82
81
|
this.setShape(x, y, w, h);
|
|
83
|
-
}
|
|
82
|
+
}
|
|
84
83
|
|
|
85
84
|
/**
|
|
86
85
|
* set new value to the Ellipse shape
|
|
@@ -92,7 +91,7 @@ var Ellipse = window.Jay.extend({
|
|
|
92
91
|
* @param {Number} w width (diameter) of the ellipse
|
|
93
92
|
* @param {Number} h height (diameter) of the ellipse
|
|
94
93
|
*/
|
|
95
|
-
setShape
|
|
94
|
+
setShape(x, y, w, h) {
|
|
96
95
|
var hW = w / 2;
|
|
97
96
|
var hH = h / 2;
|
|
98
97
|
|
|
@@ -109,7 +108,7 @@ var Ellipse = window.Jay.extend({
|
|
|
109
108
|
this.getBounds().translate(-this.radiusV.x, -this.radiusV.y);
|
|
110
109
|
|
|
111
110
|
return this;
|
|
112
|
-
}
|
|
111
|
+
}
|
|
113
112
|
|
|
114
113
|
/**
|
|
115
114
|
* Rotate this Ellipse (counter-clockwise) by the specified angle (in radians).
|
|
@@ -120,13 +119,13 @@ var Ellipse = window.Jay.extend({
|
|
|
120
119
|
* @param {me.Vector2d|me.ObservableVector2d} [v] an optional point to rotate around
|
|
121
120
|
* @return {me.Ellipse} Reference to this object for method chaining
|
|
122
121
|
*/
|
|
123
|
-
rotate
|
|
122
|
+
rotate(angle, v) {
|
|
124
123
|
// TODO : only works for circle
|
|
125
124
|
this.pos.rotate(angle, v);
|
|
126
125
|
this.getBounds().shift(this.pos);
|
|
127
126
|
this.getBounds().translate(-this.radiusV.x, -this.radiusV.y);
|
|
128
127
|
return this;
|
|
129
|
-
}
|
|
128
|
+
}
|
|
130
129
|
|
|
131
130
|
/**
|
|
132
131
|
* Scale this Ellipse by the specified scalar.
|
|
@@ -137,7 +136,7 @@ var Ellipse = window.Jay.extend({
|
|
|
137
136
|
* @param {Number} [y=x]
|
|
138
137
|
* @return {me.Ellipse} Reference to this object for method chaining
|
|
139
138
|
*/
|
|
140
|
-
scale
|
|
139
|
+
scale(x, y) {
|
|
141
140
|
y = typeof (y) !== "undefined" ? y : x;
|
|
142
141
|
return this.setShape(
|
|
143
142
|
this.pos.x,
|
|
@@ -145,7 +144,7 @@ var Ellipse = window.Jay.extend({
|
|
|
145
144
|
this.radiusV.x * 2 * x,
|
|
146
145
|
this.radiusV.y * 2 * y
|
|
147
146
|
);
|
|
148
|
-
}
|
|
147
|
+
}
|
|
149
148
|
|
|
150
149
|
/**
|
|
151
150
|
* Scale this Ellipse by the specified vector.
|
|
@@ -155,9 +154,9 @@ var Ellipse = window.Jay.extend({
|
|
|
155
154
|
* @param {me.Vector2d} v
|
|
156
155
|
* @return {me.Ellipse} Reference to this object for method chaining
|
|
157
156
|
*/
|
|
158
|
-
scaleV
|
|
157
|
+
scaleV(v) {
|
|
159
158
|
return this.scale(v.x, v.y);
|
|
160
|
-
}
|
|
159
|
+
}
|
|
161
160
|
|
|
162
161
|
/**
|
|
163
162
|
* apply the given transformation matrix to this ellipse
|
|
@@ -167,10 +166,10 @@ var Ellipse = window.Jay.extend({
|
|
|
167
166
|
* @param {me.Matrix2d} matrix the transformation matrix
|
|
168
167
|
* @return {me.Polygon} Reference to this object for method chaining
|
|
169
168
|
*/
|
|
170
|
-
transform
|
|
169
|
+
transform(/* m */) {
|
|
171
170
|
// TODO
|
|
172
171
|
return this;
|
|
173
|
-
}
|
|
172
|
+
}
|
|
174
173
|
|
|
175
174
|
/**
|
|
176
175
|
* translate the circle/ellipse by the specified offset
|
|
@@ -189,7 +188,7 @@ var Ellipse = window.Jay.extend({
|
|
|
189
188
|
* @param {me.Vector2d} v vector offset
|
|
190
189
|
* @return {me.Ellipse} this ellipse
|
|
191
190
|
*/
|
|
192
|
-
translate
|
|
191
|
+
translate() {
|
|
193
192
|
var _x, _y;
|
|
194
193
|
|
|
195
194
|
if (arguments.length === 2) {
|
|
@@ -207,7 +206,7 @@ var Ellipse = window.Jay.extend({
|
|
|
207
206
|
this.getBounds().translate(_x, _y);
|
|
208
207
|
|
|
209
208
|
return this;
|
|
210
|
-
}
|
|
209
|
+
}
|
|
211
210
|
|
|
212
211
|
/**
|
|
213
212
|
* check if this circle/ellipse contains the specified point
|
|
@@ -227,7 +226,7 @@ var Ellipse = window.Jay.extend({
|
|
|
227
226
|
* @param {Number} y y coordinate
|
|
228
227
|
* @return {boolean} true if contains
|
|
229
228
|
*/
|
|
230
|
-
contains
|
|
229
|
+
contains() {
|
|
231
230
|
var _x, _y;
|
|
232
231
|
|
|
233
232
|
if (arguments.length === 2) {
|
|
@@ -248,7 +247,7 @@ var Ellipse = window.Jay.extend({
|
|
|
248
247
|
((_x * _x) / this.radiusSq.x) +
|
|
249
248
|
((_y * _y) / this.radiusSq.y)
|
|
250
249
|
) <= 1.0;
|
|
251
|
-
}
|
|
250
|
+
}
|
|
252
251
|
|
|
253
252
|
/**
|
|
254
253
|
* returns the bounding box for this shape, the smallest Rectangle object completely containing this shape.
|
|
@@ -257,12 +256,12 @@ var Ellipse = window.Jay.extend({
|
|
|
257
256
|
* @function
|
|
258
257
|
* @return {me.Bounds} this shape bounding box Rectangle object
|
|
259
258
|
*/
|
|
260
|
-
getBounds
|
|
259
|
+
getBounds() {
|
|
261
260
|
if (typeof this._bounds === "undefined") {
|
|
262
261
|
this._bounds = pool.pull("Bounds");
|
|
263
262
|
}
|
|
264
263
|
return this._bounds;
|
|
265
|
-
}
|
|
264
|
+
}
|
|
266
265
|
|
|
267
266
|
/**
|
|
268
267
|
* clone this Ellipse
|
|
@@ -271,7 +270,7 @@ var Ellipse = window.Jay.extend({
|
|
|
271
270
|
* @function
|
|
272
271
|
* @return {me.Ellipse} new Ellipse
|
|
273
272
|
*/
|
|
274
|
-
clone
|
|
273
|
+
clone() {
|
|
275
274
|
return new Ellipse(
|
|
276
275
|
this.pos.x,
|
|
277
276
|
this.pos.y,
|
|
@@ -279,5 +278,6 @@ var Ellipse = window.Jay.extend({
|
|
|
279
278
|
this.radiusV.y * 2
|
|
280
279
|
);
|
|
281
280
|
}
|
|
282
|
-
}
|
|
281
|
+
};
|
|
282
|
+
|
|
283
283
|
export default Ellipse;
|
package/src/shapes/line.js
CHANGED
|
@@ -2,7 +2,8 @@ import Vector2d from "./../math/vector2.js";
|
|
|
2
2
|
import Polygon from "./poly.js";
|
|
3
3
|
|
|
4
4
|
/**
|
|
5
|
-
*
|
|
5
|
+
* @classdesc
|
|
6
|
+
* a line segment Object
|
|
6
7
|
* @class
|
|
7
8
|
* @extends me.Polygon
|
|
8
9
|
* @memberOf me
|
|
@@ -11,7 +12,8 @@ import Polygon from "./poly.js";
|
|
|
11
12
|
* @param {Number} y origin point of the Line
|
|
12
13
|
* @param {me.Vector2d[]} points array of vectors defining the Line
|
|
13
14
|
*/
|
|
14
|
-
|
|
15
|
+
|
|
16
|
+
class Line extends Polygon {
|
|
15
17
|
|
|
16
18
|
/**
|
|
17
19
|
* Returns true if the Line contains the given point
|
|
@@ -31,7 +33,7 @@ var Line = Polygon.extend({
|
|
|
31
33
|
* @param {Number} y y coordinate
|
|
32
34
|
* @return {boolean} true if contains
|
|
33
35
|
*/
|
|
34
|
-
contains
|
|
36
|
+
contains() {
|
|
35
37
|
var _x, _y;
|
|
36
38
|
|
|
37
39
|
if (arguments.length === 2) {
|
|
@@ -53,7 +55,7 @@ var Line = Polygon.extend({
|
|
|
53
55
|
|
|
54
56
|
//(Cy - Ay) * (Bx - Ax) = (By - Ay) * (Cx - Ax)
|
|
55
57
|
return (_y - start.y) * (end.x - start.x) === (end.y - start.y) * (_x - start.x);
|
|
56
|
-
}
|
|
58
|
+
}
|
|
57
59
|
|
|
58
60
|
/**
|
|
59
61
|
* Computes the calculated collision edges and normals.
|
|
@@ -62,7 +64,7 @@ var Line = Polygon.extend({
|
|
|
62
64
|
* @memberOf me.Line.prototype
|
|
63
65
|
* @function
|
|
64
66
|
*/
|
|
65
|
-
recalc
|
|
67
|
+
recalc() {
|
|
66
68
|
var edges = this.edges;
|
|
67
69
|
var normals = this.normals;
|
|
68
70
|
var indices = this.indices;
|
|
@@ -89,7 +91,7 @@ var Line = Polygon.extend({
|
|
|
89
91
|
indices.length = 0;
|
|
90
92
|
|
|
91
93
|
return this;
|
|
92
|
-
}
|
|
94
|
+
}
|
|
93
95
|
|
|
94
96
|
/**
|
|
95
97
|
* clone this line segment
|
|
@@ -98,12 +100,14 @@ var Line = Polygon.extend({
|
|
|
98
100
|
* @function
|
|
99
101
|
* @return {me.Line} new Line
|
|
100
102
|
*/
|
|
101
|
-
clone
|
|
103
|
+
clone() {
|
|
102
104
|
var copy = [];
|
|
103
105
|
this.points.forEach(function (point) {
|
|
104
106
|
copy.push(point.clone());
|
|
105
107
|
});
|
|
106
108
|
return new Line(this.pos.x, this.pos.y, copy);
|
|
107
109
|
}
|
|
108
|
-
|
|
110
|
+
|
|
111
|
+
};
|
|
112
|
+
|
|
109
113
|
export default Line;
|