melonjs 10.3.0 → 10.4.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/README.md +6 -6
- package/dist/melonjs.js +2419 -3072
- package/dist/melonjs.min.js +3 -3
- package/dist/melonjs.module.d.ts +3417 -3816
- package/dist/melonjs.module.js +2737 -3002
- package/package.json +16 -16
- package/src/audio/audio.js +29 -30
- package/src/camera/camera2d.js +46 -56
- package/src/entity/draggable.js +12 -13
- package/src/entity/droptarget.js +13 -15
- package/src/entity/entity.js +30 -36
- package/src/game.js +21 -22
- package/src/geometries/ellipse.js +40 -46
- package/src/geometries/line.js +9 -11
- package/src/geometries/poly.js +53 -53
- package/src/geometries/rectangle.js +42 -44
- package/src/index.js +4 -14
- package/src/input/gamepad.js +11 -10
- package/src/input/input.js +2 -3
- package/src/input/keyboard.js +113 -113
- package/src/input/pointer.js +30 -31
- package/src/input/pointerevent.js +26 -26
- package/src/lang/deprecated.js +25 -6
- package/src/level/level.js +23 -24
- package/src/level/tiled/TMXGroup.js +7 -8
- package/src/level/tiled/TMXLayer.js +30 -32
- package/src/level/tiled/TMXObject.js +21 -21
- package/src/level/tiled/TMXTile.js +18 -18
- package/src/level/tiled/TMXTileMap.js +37 -44
- package/src/level/tiled/TMXTileset.js +12 -15
- package/src/level/tiled/TMXTilesetGroup.js +9 -9
- package/src/level/tiled/renderer/TMXHexagonalRenderer.js +7 -8
- package/src/level/tiled/renderer/TMXIsometricRenderer.js +7 -8
- package/src/level/tiled/renderer/TMXOrthogonalRenderer.js +4 -5
- package/src/level/tiled/renderer/TMXRenderer.js +24 -25
- package/src/level/tiled/renderer/TMXStaggeredRenderer.js +1 -4
- package/src/loader/loader.js +14 -15
- package/src/loader/loadingscreen.js +2 -4
- package/src/math/color.js +47 -66
- package/src/math/math.js +15 -16
- package/src/math/matrix2.js +53 -58
- package/src/math/matrix3.js +56 -62
- package/src/math/observable_vector2.js +75 -76
- package/src/math/observable_vector3.js +79 -80
- package/src/math/vector2.js +91 -92
- package/src/math/vector3.js +94 -96
- package/src/particles/emitter.js +38 -40
- package/src/particles/particle.js +4 -5
- package/src/particles/particlecontainer.js +2 -3
- package/src/physics/body.js +44 -142
- package/src/physics/bounds.js +47 -47
- package/src/physics/collision.js +13 -14
- package/src/physics/detector.js +14 -14
- package/src/physics/quadtree.js +17 -19
- package/src/physics/sat.js +26 -26
- package/src/physics/world.js +24 -28
- package/src/plugin/plugin.js +11 -14
- package/src/renderable/GUI.js +41 -46
- package/src/renderable/collectable.js +4 -8
- package/src/renderable/colorlayer.js +6 -10
- package/src/renderable/container.js +87 -72
- package/src/renderable/imagelayer.js +25 -31
- package/src/renderable/nineslicesprite.js +41 -41
- package/src/renderable/renderable.js +112 -122
- package/src/renderable/sprite.js +62 -68
- package/src/renderable/trigger.js +25 -30
- package/src/state/stage.js +13 -17
- package/src/state/state.js +26 -27
- package/src/system/device.js +74 -75
- package/src/system/event.js +71 -72
- package/src/system/pooling.js +11 -12
- package/src/system/save.js +3 -4
- package/src/system/timer.js +19 -20
- package/src/text/bitmaptext.js +57 -54
- package/src/text/bitmaptextdata.js +10 -10
- package/src/text/glyph.js +3 -0
- package/src/text/text.js +44 -49
- package/src/tweens/easing.js +1 -1
- package/src/tweens/interpolation.js +1 -1
- package/src/tweens/tween.js +43 -44
- package/src/utils/agent.js +3 -4
- package/src/utils/array.js +4 -5
- package/src/utils/file.js +3 -4
- package/src/utils/function.js +4 -5
- package/src/utils/string.js +7 -9
- package/src/utils/utils.js +4 -5
- package/src/video/canvas/canvas_renderer.js +58 -59
- package/src/video/renderer.js +49 -53
- package/src/video/texture.js +98 -111
- package/src/video/texture_cache.js +2 -2
- package/src/video/video.js +15 -16
- package/src/video/webgl/glshader.js +37 -38
- package/src/video/webgl/webgl_compositor.js +31 -32
- package/src/video/webgl/webgl_renderer.js +79 -80
package/src/entity/droptarget.js
CHANGED
|
@@ -4,16 +4,14 @@ import Entity from "./entity.js";
|
|
|
4
4
|
/**
|
|
5
5
|
* @classdesc
|
|
6
6
|
* Used to make a game entity a droptarget
|
|
7
|
-
* @
|
|
8
|
-
* @augments me.Entity
|
|
9
|
-
* @memberof me
|
|
10
|
-
* @param {number} x the x coordinates of the entity object
|
|
11
|
-
* @param {number} y the y coordinates of the entity object
|
|
12
|
-
* @param {object} settings Entity properties (see {@link me.Entity})
|
|
7
|
+
* @augments Entity
|
|
13
8
|
*/
|
|
14
|
-
|
|
15
9
|
class DroptargetEntity extends Entity {
|
|
16
|
-
|
|
10
|
+
/**
|
|
11
|
+
* @param {number} x the x coordinates of the entity object
|
|
12
|
+
* @param {number} y the y coordinates of the entity object
|
|
13
|
+
* @param {object} settings Entity properties (see {@link Entity})
|
|
14
|
+
*/
|
|
17
15
|
constructor(x, y, settings) {
|
|
18
16
|
super(x, y, settings);
|
|
19
17
|
/**
|
|
@@ -22,7 +20,7 @@ class DroptargetEntity extends Entity {
|
|
|
22
20
|
* @constant
|
|
23
21
|
* @type {string}
|
|
24
22
|
* @name CHECKMETHOD_OVERLAP
|
|
25
|
-
* @memberof
|
|
23
|
+
* @memberof DroptargetEntity
|
|
26
24
|
*/
|
|
27
25
|
this.CHECKMETHOD_OVERLAP = "overlaps";
|
|
28
26
|
/**
|
|
@@ -31,7 +29,7 @@ class DroptargetEntity extends Entity {
|
|
|
31
29
|
* @constant
|
|
32
30
|
* @type {string}
|
|
33
31
|
* @name CHECKMETHOD_CONTAINS
|
|
34
|
-
* @memberof
|
|
32
|
+
* @memberof DroptargetEntity
|
|
35
33
|
*/
|
|
36
34
|
this.CHECKMETHOD_CONTAINS = "contains";
|
|
37
35
|
/**
|
|
@@ -40,7 +38,7 @@ class DroptargetEntity extends Entity {
|
|
|
40
38
|
* @constant
|
|
41
39
|
* @type {string}
|
|
42
40
|
* @name checkMethod
|
|
43
|
-
* @memberof
|
|
41
|
+
* @memberof DroptargetEntity
|
|
44
42
|
*/
|
|
45
43
|
this.checkMethod = null;
|
|
46
44
|
event.on(event.DRAGEND, this.checkOnMe, this);
|
|
@@ -50,7 +48,7 @@ class DroptargetEntity extends Entity {
|
|
|
50
48
|
/**
|
|
51
49
|
* Sets the collision method which is going to be used to check a valid drop
|
|
52
50
|
* @name setCheckMethod
|
|
53
|
-
* @memberof
|
|
51
|
+
* @memberof DroptargetEntity
|
|
54
52
|
* @function
|
|
55
53
|
* @param {string} checkMethod the checkmethod (defaults to CHECKMETHOD_OVERLAP)
|
|
56
54
|
*/
|
|
@@ -65,7 +63,7 @@ class DroptargetEntity extends Entity {
|
|
|
65
63
|
/**
|
|
66
64
|
* Checks if a dropped entity is dropped on the current entity
|
|
67
65
|
* @name checkOnMe
|
|
68
|
-
* @memberof
|
|
66
|
+
* @memberof DroptargetEntity
|
|
69
67
|
* @function
|
|
70
68
|
* @param {object} e the triggering event
|
|
71
69
|
* @param {object} draggableEntity the draggable entity that is dropped
|
|
@@ -80,7 +78,7 @@ class DroptargetEntity extends Entity {
|
|
|
80
78
|
/**
|
|
81
79
|
* Gets called when a draggable entity is dropped on the current entity
|
|
82
80
|
* @name drop
|
|
83
|
-
* @memberof
|
|
81
|
+
* @memberof DroptargetEntity
|
|
84
82
|
* @function
|
|
85
83
|
* @param {object} draggableEntity the draggable entity that is dropped
|
|
86
84
|
*/
|
|
@@ -91,7 +89,7 @@ class DroptargetEntity extends Entity {
|
|
|
91
89
|
/**
|
|
92
90
|
* Destructor
|
|
93
91
|
* @name destroy
|
|
94
|
-
* @memberof
|
|
92
|
+
* @memberof DroptargetEntity
|
|
95
93
|
* @function
|
|
96
94
|
*/
|
|
97
95
|
destroy() {
|
package/src/entity/entity.js
CHANGED
|
@@ -8,32 +8,26 @@ import Polygon from "./../geometries/poly.js";
|
|
|
8
8
|
/**
|
|
9
9
|
* @classdesc
|
|
10
10
|
* a Generic Object Entity
|
|
11
|
-
* @
|
|
12
|
-
* @
|
|
13
|
-
* @memberof me
|
|
14
|
-
* @see me.Renderable
|
|
15
|
-
* @param {number} x the x coordinates of the entity object
|
|
16
|
-
* @param {number} y the y coordinates of the entity object
|
|
17
|
-
* @param {object} settings Entity properties, to be defined through Tiled or when calling the entity constructor
|
|
18
|
-
* <img src="images/object_properties.png"/>
|
|
19
|
-
* @param {number} settings.width the physical width the entity takes up in game
|
|
20
|
-
* @param {number} settings.height the physical height the entity takes up in game
|
|
21
|
-
* @param {string} [settings.name] object entity name
|
|
22
|
-
* @param {string} [settings.id] object unique IDs
|
|
23
|
-
* @param {Image|string} [settings.image] resource name of a spritesheet to use for the entity renderable component
|
|
24
|
-
* @param {me.Vector2d} [settings.anchorPoint=0.0] Entity anchor point
|
|
25
|
-
* @param {number} [settings.framewidth=settings.width] width of a single frame in the given spritesheet
|
|
26
|
-
* @param {number} [settings.frameheight=settings.width] height of a single frame in the given spritesheet
|
|
27
|
-
* @param {string} [settings.type] object type
|
|
28
|
-
* @param {number} [settings.collisionMask] Mask collision detection for this object
|
|
29
|
-
* @param {me.Rect[]|me.Polygon[]|me.Line[]|me.Ellipse[]} [settings.shapes] the initial list of collision shapes (usually populated through Tiled)
|
|
11
|
+
* @augments Renderable
|
|
12
|
+
* @see Renderable
|
|
30
13
|
*/
|
|
31
|
-
|
|
32
14
|
class Entity extends Renderable {
|
|
33
|
-
|
|
34
|
-
|
|
35
15
|
/**
|
|
36
|
-
* @
|
|
16
|
+
* @param {number} x the x coordinates of the entity object
|
|
17
|
+
* @param {number} y the y coordinates of the entity object
|
|
18
|
+
* @param {object} settings Entity properties, to be defined through Tiled or when calling the entity constructor
|
|
19
|
+
* <img src="images/object_properties.png"/>
|
|
20
|
+
* @param {number} settings.width the physical width the entity takes up in game
|
|
21
|
+
* @param {number} settings.height the physical height the entity takes up in game
|
|
22
|
+
* @param {string} [settings.name] object entity name
|
|
23
|
+
* @param {string} [settings.id] object unique IDs
|
|
24
|
+
* @param {Image|string} [settings.image] resource name of a spritesheet to use for the entity renderable component
|
|
25
|
+
* @param {Vector2d} [settings.anchorPoint=0.0] Entity anchor point
|
|
26
|
+
* @param {number} [settings.framewidth=settings.width] width of a single frame in the given spritesheet
|
|
27
|
+
* @param {number} [settings.frameheight=settings.width] height of a single frame in the given spritesheet
|
|
28
|
+
* @param {string} [settings.type] object type
|
|
29
|
+
* @param {number} [settings.collisionMask] Mask collision detection for this object
|
|
30
|
+
* @param {Rect[]|Polygon[]|Line[]|Ellipse[]} [settings.shapes] the initial list of collision shapes (usually populated through Tiled)
|
|
37
31
|
*/
|
|
38
32
|
constructor(x, y, settings) {
|
|
39
33
|
|
|
@@ -76,7 +70,7 @@ class Entity extends Renderable {
|
|
|
76
70
|
* @public
|
|
77
71
|
* @type {string}
|
|
78
72
|
* @name type
|
|
79
|
-
* @memberof
|
|
73
|
+
* @memberof Entity
|
|
80
74
|
*/
|
|
81
75
|
this.type = settings.type || "";
|
|
82
76
|
|
|
@@ -85,7 +79,7 @@ class Entity extends Renderable {
|
|
|
85
79
|
* @public
|
|
86
80
|
* @type {number}
|
|
87
81
|
* @name id
|
|
88
|
-
* @memberof
|
|
82
|
+
* @memberof Entity
|
|
89
83
|
*/
|
|
90
84
|
this.id = settings.id || "";
|
|
91
85
|
|
|
@@ -95,16 +89,16 @@ class Entity extends Renderable {
|
|
|
95
89
|
* @public
|
|
96
90
|
* @type {boolean}
|
|
97
91
|
* @name alive
|
|
98
|
-
* @memberof
|
|
92
|
+
* @memberof Entity
|
|
99
93
|
*/
|
|
100
94
|
this.alive = true;
|
|
101
95
|
|
|
102
96
|
/**
|
|
103
97
|
* the entity body object
|
|
104
98
|
* @public
|
|
105
|
-
* @type {
|
|
99
|
+
* @type {Body}
|
|
106
100
|
* @name body
|
|
107
|
-
* @memberof
|
|
101
|
+
* @memberof Entity
|
|
108
102
|
*/
|
|
109
103
|
// initialize the default body
|
|
110
104
|
if (typeof settings.shapes === "undefined") {
|
|
@@ -134,9 +128,9 @@ class Entity extends Renderable {
|
|
|
134
128
|
/**
|
|
135
129
|
* The entity renderable component (can be any objects deriving from me.Renderable, like me.Sprite for example)
|
|
136
130
|
* @public
|
|
137
|
-
* @type {
|
|
131
|
+
* @type {Renderable}
|
|
138
132
|
* @name renderable
|
|
139
|
-
* @memberof
|
|
133
|
+
* @memberof Entity
|
|
140
134
|
*/
|
|
141
135
|
|
|
142
136
|
get renderable() {
|
|
@@ -164,9 +158,9 @@ class Entity extends Renderable {
|
|
|
164
158
|
* update the bounds position when the body is modified
|
|
165
159
|
* @ignore
|
|
166
160
|
* @name onBodyUpdate
|
|
167
|
-
* @memberof
|
|
161
|
+
* @memberof Entity
|
|
168
162
|
* @function
|
|
169
|
-
* @param {
|
|
163
|
+
* @param {Body} body the body whose bounds to update
|
|
170
164
|
*/
|
|
171
165
|
onBodyUpdate(body) {
|
|
172
166
|
// update the entity bounds to include the body bounds
|
|
@@ -200,11 +194,11 @@ class Entity extends Renderable {
|
|
|
200
194
|
* not to be called by the end user<br>
|
|
201
195
|
* called by the game manager on each game loop
|
|
202
196
|
* @name draw
|
|
203
|
-
* @memberof
|
|
197
|
+
* @memberof Entity
|
|
204
198
|
* @function
|
|
205
199
|
* @protected
|
|
206
|
-
* @param {
|
|
207
|
-
* @param {
|
|
200
|
+
* @param {CanvasRenderer|WebGLRenderer} renderer a renderer object
|
|
201
|
+
* @param {Rect} rect region to draw
|
|
208
202
|
*/
|
|
209
203
|
draw(renderer, rect) {
|
|
210
204
|
var renderable = this.renderable;
|
|
@@ -239,7 +233,7 @@ class Entity extends Renderable {
|
|
|
239
233
|
* onDeactivateEvent Notification function<br>
|
|
240
234
|
* Called by engine before deleting the object
|
|
241
235
|
* @name onDeactivateEvent
|
|
242
|
-
* @memberof
|
|
236
|
+
* @memberof Entity
|
|
243
237
|
* @function
|
|
244
238
|
*/
|
|
245
239
|
onDeactivateEvent() {
|
package/src/game.js
CHANGED
|
@@ -8,8 +8,7 @@ import World from "./physics/world.js";
|
|
|
8
8
|
* me.game represents your current game, it contains all the objects,
|
|
9
9
|
* tilemap layers, current viewport, collision map, etc...<br>
|
|
10
10
|
* me.game is also responsible for updating (each frame) the object status and draw them.
|
|
11
|
-
* @namespace
|
|
12
|
-
* @memberof me
|
|
11
|
+
* @namespace game
|
|
13
12
|
*/
|
|
14
13
|
|
|
15
14
|
// to know when we have to refresh the display
|
|
@@ -47,9 +46,9 @@ event.on(event.BOOT, () => {
|
|
|
47
46
|
/**
|
|
48
47
|
* a reference to the current active stage "default" camera
|
|
49
48
|
* @public
|
|
50
|
-
* @type {
|
|
49
|
+
* @type {Camera2d}
|
|
51
50
|
* @name viewport
|
|
52
|
-
* @memberof
|
|
51
|
+
* @memberof game
|
|
53
52
|
*/
|
|
54
53
|
export let viewport;
|
|
55
54
|
|
|
@@ -57,9 +56,9 @@ export let viewport;
|
|
|
57
56
|
* a reference to the game world, <br>
|
|
58
57
|
* a world is a virtual environment containing all the game objects
|
|
59
58
|
* @public
|
|
60
|
-
* @type {
|
|
59
|
+
* @type {World}
|
|
61
60
|
* @name world
|
|
62
|
-
* @memberof
|
|
61
|
+
* @memberof game
|
|
63
62
|
*/
|
|
64
63
|
export let world;
|
|
65
64
|
|
|
@@ -70,7 +69,7 @@ export let world;
|
|
|
70
69
|
* @type {boolean}
|
|
71
70
|
* @default true
|
|
72
71
|
* @name mergeGroup
|
|
73
|
-
* @memberof
|
|
72
|
+
* @memberof game
|
|
74
73
|
*/
|
|
75
74
|
export let mergeGroup = true;
|
|
76
75
|
|
|
@@ -81,7 +80,7 @@ export let mergeGroup = true;
|
|
|
81
80
|
* @type {string}
|
|
82
81
|
* @default "z"
|
|
83
82
|
* @name sortOn
|
|
84
|
-
* @memberof
|
|
83
|
+
* @memberof game
|
|
85
84
|
*/
|
|
86
85
|
export let sortOn = "z";
|
|
87
86
|
|
|
@@ -93,14 +92,14 @@ export let sortOn = "z";
|
|
|
93
92
|
* @public
|
|
94
93
|
* @type {DOMHighResTimeStamp}
|
|
95
94
|
* @name lastUpdate
|
|
96
|
-
* @memberof
|
|
95
|
+
* @memberof game
|
|
97
96
|
*/
|
|
98
97
|
export let lastUpdate = window.performance.now();
|
|
99
98
|
|
|
100
99
|
/**
|
|
101
100
|
* Fired when a level is fully loaded and all entities instantiated. <br>
|
|
102
101
|
* Additionnaly the level id will also be passed to the called function.
|
|
103
|
-
* @function
|
|
102
|
+
* @function game.onLevelLoaded
|
|
104
103
|
* @example
|
|
105
104
|
* // call myFunction () everytime a level is loaded
|
|
106
105
|
* me.game.onLevelLoaded = this.myFunction.bind(this);
|
|
@@ -110,7 +109,7 @@ export function onLevelLoaded() {};
|
|
|
110
109
|
/**
|
|
111
110
|
* reset the game Object manager<br>
|
|
112
111
|
* destroy all current objects
|
|
113
|
-
* @function
|
|
112
|
+
* @function game.reset
|
|
114
113
|
*/
|
|
115
114
|
export function reset () {
|
|
116
115
|
// point to the current active stage "default" camera
|
|
@@ -128,9 +127,9 @@ export function reset () {
|
|
|
128
127
|
|
|
129
128
|
/**
|
|
130
129
|
* Update the renderer framerate using the system config variables.
|
|
131
|
-
* @function
|
|
132
|
-
* @see
|
|
133
|
-
* @see
|
|
130
|
+
* @function game.updateFrameRate
|
|
131
|
+
* @see timer.maxfps
|
|
132
|
+
* @see World.fps
|
|
134
133
|
*/
|
|
135
134
|
export function updateFrameRate() {
|
|
136
135
|
// reset the frame counter
|
|
@@ -149,9 +148,9 @@ export function updateFrameRate() {
|
|
|
149
148
|
|
|
150
149
|
/**
|
|
151
150
|
* Returns the parent container of the specified Child in the game world
|
|
152
|
-
* @function
|
|
153
|
-
* @param {
|
|
154
|
-
* @returns {
|
|
151
|
+
* @function game.getParentContainer
|
|
152
|
+
* @param {Renderable} child
|
|
153
|
+
* @returns {Container}
|
|
155
154
|
*/
|
|
156
155
|
export function getParentContainer(child) {
|
|
157
156
|
return child.ancestor;
|
|
@@ -159,7 +158,7 @@ export function getParentContainer(child) {
|
|
|
159
158
|
|
|
160
159
|
/**
|
|
161
160
|
* force the redraw (not update) of all objects
|
|
162
|
-
* @function
|
|
161
|
+
* @function game.repaint
|
|
163
162
|
*/
|
|
164
163
|
export function repaint() {
|
|
165
164
|
isDirty = true;
|
|
@@ -169,9 +168,9 @@ export function repaint() {
|
|
|
169
168
|
/**
|
|
170
169
|
* update all objects of the game manager
|
|
171
170
|
* @ignore
|
|
172
|
-
* @function
|
|
171
|
+
* @function game.update
|
|
173
172
|
* @param {number} time current timestamp as provided by the RAF callback
|
|
174
|
-
* @param {
|
|
173
|
+
* @param {Stage} stage the current stage
|
|
175
174
|
*/
|
|
176
175
|
export function update(time, stage) {
|
|
177
176
|
// handle frame skipping if required
|
|
@@ -216,9 +215,9 @@ export function update(time, stage) {
|
|
|
216
215
|
|
|
217
216
|
/**
|
|
218
217
|
* draw the current scene/stage
|
|
219
|
-
* @function
|
|
218
|
+
* @function game.draw
|
|
220
219
|
* @ignore
|
|
221
|
-
* @param {
|
|
220
|
+
* @param {Stage} stage the current stage
|
|
222
221
|
*/
|
|
223
222
|
export function draw(stage) {
|
|
224
223
|
|
|
@@ -4,33 +4,27 @@ import pool from "./../system/pooling.js";
|
|
|
4
4
|
/**
|
|
5
5
|
* @classdesc
|
|
6
6
|
* an ellipse Object
|
|
7
|
-
* @class Ellipse
|
|
8
|
-
* @augments me.Object
|
|
9
|
-
* @memberof me
|
|
10
|
-
* @param {number} x the center x coordinate of the ellipse
|
|
11
|
-
* @param {number} y the center y coordinate of the ellipse
|
|
12
|
-
* @param {number} w width (diameter) of the ellipse
|
|
13
|
-
* @param {number} h height (diameter) of the ellipse
|
|
14
7
|
*/
|
|
15
|
-
|
|
16
8
|
class Ellipse {
|
|
17
|
-
|
|
9
|
+
/**
|
|
10
|
+
* @param {number} x the center x coordinate of the ellipse
|
|
11
|
+
* @param {number} y the center y coordinate of the ellipse
|
|
12
|
+
* @param {number} w width (diameter) of the ellipse
|
|
13
|
+
* @param {number} h height (diameter) of the ellipse
|
|
14
|
+
*/
|
|
18
15
|
constructor(x, y, w, h) {
|
|
19
16
|
/**
|
|
20
17
|
* the center coordinates of the ellipse
|
|
21
18
|
* @public
|
|
22
|
-
* @type {
|
|
19
|
+
* @type {Vector2d}
|
|
23
20
|
* @name pos
|
|
24
|
-
* @memberof
|
|
21
|
+
* @memberof Ellipse#
|
|
25
22
|
*/
|
|
26
23
|
this.pos = new Vector2d();
|
|
27
24
|
|
|
28
25
|
/**
|
|
29
26
|
* The bounding rectangle for this shape
|
|
30
27
|
* @private
|
|
31
|
-
* @type {me.Bounds}
|
|
32
|
-
* @name _bounds
|
|
33
|
-
* @memberof me.Ellipse#
|
|
34
28
|
*/
|
|
35
29
|
this._bounds = undefined;
|
|
36
30
|
|
|
@@ -39,34 +33,34 @@ class Ellipse {
|
|
|
39
33
|
* @public
|
|
40
34
|
* @type {number}
|
|
41
35
|
* @name radius
|
|
42
|
-
* @memberof
|
|
36
|
+
* @memberof Ellipse
|
|
43
37
|
*/
|
|
44
38
|
this.radius = NaN;
|
|
45
39
|
|
|
46
40
|
/**
|
|
47
41
|
* Pre-scaled radius vector for ellipse
|
|
48
42
|
* @public
|
|
49
|
-
* @type {
|
|
43
|
+
* @type {Vector2d}
|
|
50
44
|
* @name radiusV
|
|
51
|
-
* @memberof
|
|
45
|
+
* @memberof Ellipse#
|
|
52
46
|
*/
|
|
53
47
|
this.radiusV = new Vector2d();
|
|
54
48
|
|
|
55
49
|
/**
|
|
56
50
|
* Radius squared, for pythagorean theorom
|
|
57
51
|
* @public
|
|
58
|
-
* @type {
|
|
52
|
+
* @type {Vector2d}
|
|
59
53
|
* @name radiusSq
|
|
60
|
-
* @memberof
|
|
54
|
+
* @memberof Ellipse#
|
|
61
55
|
*/
|
|
62
56
|
this.radiusSq = new Vector2d();
|
|
63
57
|
|
|
64
58
|
/**
|
|
65
59
|
* x/y scaling ratio for ellipse
|
|
66
60
|
* @public
|
|
67
|
-
* @type {
|
|
61
|
+
* @type {Vector2d}
|
|
68
62
|
* @name ratio
|
|
69
|
-
* @memberof
|
|
63
|
+
* @memberof Ellipse#
|
|
70
64
|
*/
|
|
71
65
|
this.ratio = new Vector2d();
|
|
72
66
|
|
|
@@ -83,13 +77,13 @@ class Ellipse {
|
|
|
83
77
|
/**
|
|
84
78
|
* set new value to the Ellipse shape
|
|
85
79
|
* @name setShape
|
|
86
|
-
* @memberof
|
|
80
|
+
* @memberof Ellipse.prototype
|
|
87
81
|
* @function
|
|
88
82
|
* @param {number} x the center x coordinate of the ellipse
|
|
89
83
|
* @param {number} y the center y coordinate of the ellipse
|
|
90
84
|
* @param {number} w width (diameter) of the ellipse
|
|
91
85
|
* @param {number} h height (diameter) of the ellipse
|
|
92
|
-
* @returns {
|
|
86
|
+
* @returns {Ellipse} this instance for objecf chaining
|
|
93
87
|
*/
|
|
94
88
|
setShape(x, y, w, h) {
|
|
95
89
|
var hW = w / 2;
|
|
@@ -113,11 +107,11 @@ class Ellipse {
|
|
|
113
107
|
/**
|
|
114
108
|
* Rotate this Ellipse (counter-clockwise) by the specified angle (in radians).
|
|
115
109
|
* @name rotate
|
|
116
|
-
* @memberof
|
|
110
|
+
* @memberof Ellipse.prototype
|
|
117
111
|
* @function
|
|
118
112
|
* @param {number} angle The angle to rotate (in radians)
|
|
119
|
-
* @param {
|
|
120
|
-
* @returns {
|
|
113
|
+
* @param {Vector2d|ObservableVector2d} [v] an optional point to rotate around
|
|
114
|
+
* @returns {Ellipse} Reference to this object for method chaining
|
|
121
115
|
*/
|
|
122
116
|
rotate(angle, v) {
|
|
123
117
|
// TODO : only works for circle
|
|
@@ -130,11 +124,11 @@ class Ellipse {
|
|
|
130
124
|
/**
|
|
131
125
|
* Scale this Ellipse by the specified scalar.
|
|
132
126
|
* @name scale
|
|
133
|
-
* @memberof
|
|
127
|
+
* @memberof Ellipse.prototype
|
|
134
128
|
* @function
|
|
135
129
|
* @param {number} x
|
|
136
130
|
* @param {number} [y=x]
|
|
137
|
-
* @returns {
|
|
131
|
+
* @returns {Ellipse} Reference to this object for method chaining
|
|
138
132
|
*/
|
|
139
133
|
scale(x, y) {
|
|
140
134
|
y = typeof (y) !== "undefined" ? y : x;
|
|
@@ -149,10 +143,10 @@ class Ellipse {
|
|
|
149
143
|
/**
|
|
150
144
|
* Scale this Ellipse by the specified vector.
|
|
151
145
|
* @name scale
|
|
152
|
-
* @memberof
|
|
146
|
+
* @memberof Ellipse.prototype
|
|
153
147
|
* @function
|
|
154
|
-
* @param {
|
|
155
|
-
* @returns {
|
|
148
|
+
* @param {Vector2d} v
|
|
149
|
+
* @returns {Ellipse} Reference to this object for method chaining
|
|
156
150
|
*/
|
|
157
151
|
scaleV(v) {
|
|
158
152
|
return this.scale(v.x, v.y);
|
|
@@ -161,10 +155,10 @@ class Ellipse {
|
|
|
161
155
|
/**
|
|
162
156
|
* apply the given transformation matrix to this ellipse
|
|
163
157
|
* @name transform
|
|
164
|
-
* @memberof
|
|
158
|
+
* @memberof Ellipse.prototype
|
|
165
159
|
* @function
|
|
166
|
-
* @param {
|
|
167
|
-
* @returns {
|
|
160
|
+
* @param {Matrix2d} matrix the transformation matrix
|
|
161
|
+
* @returns {Polygon} Reference to this object for method chaining
|
|
168
162
|
*/
|
|
169
163
|
transform(/* m */) {
|
|
170
164
|
// TODO
|
|
@@ -174,19 +168,19 @@ class Ellipse {
|
|
|
174
168
|
/**
|
|
175
169
|
* translate the circle/ellipse by the specified offset
|
|
176
170
|
* @name translate
|
|
177
|
-
* @memberof
|
|
171
|
+
* @memberof Ellipse.prototype
|
|
178
172
|
* @function
|
|
179
173
|
* @param {number} x x offset
|
|
180
174
|
* @param {number} y y offset
|
|
181
|
-
* @returns {
|
|
175
|
+
* @returns {Ellipse} this ellipse
|
|
182
176
|
*/
|
|
183
177
|
/**
|
|
184
178
|
* translate the circle/ellipse by the specified vector
|
|
185
179
|
* @name translate
|
|
186
|
-
* @memberof
|
|
180
|
+
* @memberof Ellipse.prototype
|
|
187
181
|
* @function
|
|
188
|
-
* @param {
|
|
189
|
-
* @returns {
|
|
182
|
+
* @param {Vector2d} v vector offset
|
|
183
|
+
* @returns {Ellipse} this ellipse
|
|
190
184
|
*/
|
|
191
185
|
translate() {
|
|
192
186
|
var _x, _y;
|
|
@@ -211,16 +205,16 @@ class Ellipse {
|
|
|
211
205
|
/**
|
|
212
206
|
* check if this circle/ellipse contains the specified point
|
|
213
207
|
* @name contains
|
|
214
|
-
* @memberof
|
|
208
|
+
* @memberof Ellipse.prototype
|
|
215
209
|
* @function
|
|
216
|
-
* @param
|
|
210
|
+
* @param {Vector2d} point
|
|
217
211
|
* @returns {boolean} true if contains
|
|
218
212
|
*/
|
|
219
213
|
|
|
220
214
|
/**
|
|
221
215
|
* check if this circle/ellipse contains the specified point
|
|
222
216
|
* @name contains
|
|
223
|
-
* @memberof
|
|
217
|
+
* @memberof Ellipse.prototype
|
|
224
218
|
* @function
|
|
225
219
|
* @param {number} x x coordinate
|
|
226
220
|
* @param {number} y y coordinate
|
|
@@ -252,9 +246,9 @@ class Ellipse {
|
|
|
252
246
|
/**
|
|
253
247
|
* returns the bounding box for this shape, the smallest Rectangle object completely containing this shape.
|
|
254
248
|
* @name getBounds
|
|
255
|
-
* @memberof
|
|
249
|
+
* @memberof Ellipse.prototype
|
|
256
250
|
* @function
|
|
257
|
-
* @returns {
|
|
251
|
+
* @returns {Bounds} this shape bounding box Rectangle object
|
|
258
252
|
*/
|
|
259
253
|
getBounds() {
|
|
260
254
|
if (typeof this._bounds === "undefined") {
|
|
@@ -266,9 +260,9 @@ class Ellipse {
|
|
|
266
260
|
/**
|
|
267
261
|
* clone this Ellipse
|
|
268
262
|
* @name clone
|
|
269
|
-
* @memberof
|
|
263
|
+
* @memberof Ellipse.prototype
|
|
270
264
|
* @function
|
|
271
|
-
* @returns {
|
|
265
|
+
* @returns {Ellipse} new Ellipse
|
|
272
266
|
*/
|
|
273
267
|
clone() {
|
|
274
268
|
return new Ellipse(
|
package/src/geometries/line.js
CHANGED
|
@@ -4,12 +4,10 @@ import Polygon from "./poly.js";
|
|
|
4
4
|
/**
|
|
5
5
|
* @classdesc
|
|
6
6
|
* a line segment Object
|
|
7
|
-
* @
|
|
8
|
-
* @augments me.Polygon
|
|
9
|
-
* @memberof me
|
|
7
|
+
* @augments Polygon
|
|
10
8
|
* @param {number} x origin point of the Line
|
|
11
9
|
* @param {number} y origin point of the Line
|
|
12
|
-
* @param {
|
|
10
|
+
* @param {Vector2d[]} points array of vectors defining the Line
|
|
13
11
|
*/
|
|
14
12
|
|
|
15
13
|
class Line extends Polygon {
|
|
@@ -17,16 +15,16 @@ class Line extends Polygon {
|
|
|
17
15
|
/**
|
|
18
16
|
* Returns true if the Line contains the given point
|
|
19
17
|
* @name contains
|
|
20
|
-
* @memberof
|
|
18
|
+
* @memberof Line.prototype
|
|
21
19
|
* @function
|
|
22
|
-
* @param
|
|
20
|
+
* @param {Vector2d} point
|
|
23
21
|
* @returns {boolean} true if contains
|
|
24
22
|
*/
|
|
25
23
|
|
|
26
24
|
/**
|
|
27
25
|
* Returns true if the Line contains the given point
|
|
28
26
|
* @name contains
|
|
29
|
-
* @memberof
|
|
27
|
+
* @memberof Line.prototype
|
|
30
28
|
* @function
|
|
31
29
|
* @param {number} x x coordinate
|
|
32
30
|
* @param {number} y y coordinate
|
|
@@ -60,9 +58,9 @@ class Line extends Polygon {
|
|
|
60
58
|
* Computes the calculated collision edges and normals.
|
|
61
59
|
* This **must** be called if the `points` array, `angle`, or `offset` is modified manually.
|
|
62
60
|
* @name recalc
|
|
63
|
-
* @memberof
|
|
61
|
+
* @memberof Line.prototype
|
|
64
62
|
* @function
|
|
65
|
-
* @returns {
|
|
63
|
+
* @returns {Line} this instance for objecf chaining
|
|
66
64
|
*/
|
|
67
65
|
recalc() {
|
|
68
66
|
var edges = this.edges;
|
|
@@ -96,9 +94,9 @@ class Line extends Polygon {
|
|
|
96
94
|
/**
|
|
97
95
|
* clone this line segment
|
|
98
96
|
* @name clone
|
|
99
|
-
* @memberof
|
|
97
|
+
* @memberof Line.prototype
|
|
100
98
|
* @function
|
|
101
|
-
* @returns {
|
|
99
|
+
* @returns {Line} new Line
|
|
102
100
|
*/
|
|
103
101
|
clone() {
|
|
104
102
|
var copy = [];
|