melonjs 14.0.2 → 14.1.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 +2 -0
- package/dist/melonjs.mjs/_virtual/_commonjsHelpers.js +10 -0
- package/dist/melonjs.mjs/_virtual/arraymultimap.js +10 -0
- package/dist/melonjs.mjs/_virtual/earcut.js +10 -0
- package/dist/melonjs.mjs/_virtual/howler.js +10 -0
- package/dist/melonjs.mjs/_virtual/index.js +10 -0
- package/dist/melonjs.mjs/_virtual/index2.js +10 -0
- package/dist/melonjs.mjs/_virtual/multimap.js +10 -0
- package/dist/melonjs.mjs/_virtual/setmultimap.js +10 -0
- package/dist/melonjs.mjs/application/application.js +240 -0
- package/dist/melonjs.mjs/audio/audio.js +536 -0
- package/dist/melonjs.mjs/camera/camera2d.js +732 -0
- package/dist/melonjs.mjs/entity/entity.js +248 -0
- package/dist/melonjs.mjs/game.js +29 -0
- package/dist/melonjs.mjs/geometries/ellipse.js +275 -0
- package/dist/melonjs.mjs/geometries/line.js +116 -0
- package/dist/melonjs.mjs/geometries/path2d.js +319 -0
- package/dist/melonjs.mjs/geometries/point.js +89 -0
- package/dist/melonjs.mjs/geometries/poly.js +500 -0
- package/dist/melonjs.mjs/geometries/rectangle.js +375 -0
- package/dist/melonjs.mjs/geometries/roundrect.js +168 -0
- package/dist/melonjs.mjs/index.js +248 -0
- package/dist/melonjs.mjs/input/gamepad.js +501 -0
- package/dist/melonjs.mjs/input/input.js +26 -0
- package/dist/melonjs.mjs/input/keyboard.js +470 -0
- package/dist/melonjs.mjs/input/pointer.js +393 -0
- package/dist/melonjs.mjs/input/pointerevent.js +818 -0
- package/dist/melonjs.mjs/lang/deprecated.js +157 -0
- package/dist/melonjs.mjs/level/level.js +297 -0
- package/dist/melonjs.mjs/level/tiled/TMXGroup.js +141 -0
- package/dist/melonjs.mjs/level/tiled/TMXLayer.js +448 -0
- package/dist/melonjs.mjs/level/tiled/TMXObject.js +355 -0
- package/dist/melonjs.mjs/level/tiled/TMXTile.js +194 -0
- package/dist/melonjs.mjs/level/tiled/TMXTileMap.js +639 -0
- package/dist/melonjs.mjs/level/tiled/TMXTileset.js +311 -0
- package/dist/melonjs.mjs/level/tiled/TMXTilesetGroup.js +83 -0
- package/dist/melonjs.mjs/level/tiled/TMXUtils.js +367 -0
- package/dist/melonjs.mjs/level/tiled/renderer/TMXHexagonalRenderer.js +506 -0
- package/dist/melonjs.mjs/level/tiled/renderer/TMXIsometricRenderer.js +220 -0
- package/dist/melonjs.mjs/level/tiled/renderer/TMXOrthogonalRenderer.js +157 -0
- package/dist/melonjs.mjs/level/tiled/renderer/TMXRenderer.js +125 -0
- package/dist/melonjs.mjs/level/tiled/renderer/TMXStaggeredRenderer.js +109 -0
- package/dist/melonjs.mjs/loader/loader.js +801 -0
- package/dist/melonjs.mjs/loader/loadingscreen.js +120 -0
- package/dist/melonjs.mjs/loader/melonjs_logo.png.js +11 -0
- package/dist/melonjs.mjs/math/color.js +618 -0
- package/dist/melonjs.mjs/math/math.js +218 -0
- package/dist/melonjs.mjs/math/matrix2.js +503 -0
- package/dist/melonjs.mjs/math/matrix3.js +681 -0
- package/dist/melonjs.mjs/math/observable_vector2.js +471 -0
- package/dist/melonjs.mjs/math/observable_vector3.js +561 -0
- package/dist/melonjs.mjs/math/vector2.js +528 -0
- package/dist/melonjs.mjs/math/vector3.js +569 -0
- package/dist/melonjs.mjs/node_modules/@teppeis/multimaps/dist/src/arraymultimap.js +73 -0
- package/dist/melonjs.mjs/node_modules/@teppeis/multimaps/dist/src/index.js +21 -0
- package/dist/melonjs.mjs/node_modules/@teppeis/multimaps/dist/src/multimap.js +324 -0
- package/dist/melonjs.mjs/node_modules/@teppeis/multimaps/dist/src/setmultimap.js +69 -0
- package/dist/melonjs.mjs/node_modules/earcut/src/earcut.js +691 -0
- package/dist/melonjs.mjs/node_modules/eventemitter3/index.js +350 -0
- package/dist/melonjs.mjs/node_modules/howler/dist/howler.js +3241 -0
- package/dist/melonjs.mjs/particles/emitter.js +267 -0
- package/dist/melonjs.mjs/particles/particle.js +188 -0
- package/dist/melonjs.mjs/particles/settings.js +319 -0
- package/dist/melonjs.mjs/physics/body.js +704 -0
- package/dist/melonjs.mjs/physics/bounds.js +460 -0
- package/dist/melonjs.mjs/physics/collision.js +132 -0
- package/dist/melonjs.mjs/physics/detector.js +194 -0
- package/dist/melonjs.mjs/physics/quadtree.js +391 -0
- package/dist/melonjs.mjs/physics/response.js +57 -0
- package/dist/melonjs.mjs/physics/sat.js +483 -0
- package/dist/melonjs.mjs/physics/world.js +221 -0
- package/dist/melonjs.mjs/plugin/plugin.js +141 -0
- package/dist/melonjs.mjs/renderable/collectable.js +62 -0
- package/dist/melonjs.mjs/renderable/colorlayer.js +80 -0
- package/dist/melonjs.mjs/renderable/container.js +1018 -0
- package/dist/melonjs.mjs/renderable/dragndrop.js +224 -0
- package/dist/melonjs.mjs/renderable/imagelayer.js +306 -0
- package/dist/melonjs.mjs/renderable/light2d.js +156 -0
- package/dist/melonjs.mjs/renderable/nineslicesprite.js +247 -0
- package/dist/melonjs.mjs/renderable/renderable.js +783 -0
- package/dist/melonjs.mjs/renderable/sprite.js +654 -0
- package/dist/melonjs.mjs/renderable/trigger.js +157 -0
- package/dist/melonjs.mjs/renderable/ui/uibaseelement.js +213 -0
- package/dist/melonjs.mjs/renderable/ui/uispriteelement.js +226 -0
- package/dist/melonjs.mjs/renderable/ui/uitextbutton.js +128 -0
- package/dist/melonjs.mjs/state/stage.js +237 -0
- package/dist/melonjs.mjs/state/state.js +596 -0
- package/dist/melonjs.mjs/system/device.js +909 -0
- package/dist/melonjs.mjs/system/dom.js +78 -0
- package/dist/melonjs.mjs/system/event.js +537 -0
- package/dist/melonjs.mjs/system/platform.js +41 -0
- package/dist/melonjs.mjs/system/pooling.js +209 -0
- package/dist/melonjs.mjs/system/save.js +157 -0
- package/dist/melonjs.mjs/system/timer.js +286 -0
- package/dist/melonjs.mjs/text/bitmaptext.js +364 -0
- package/dist/melonjs.mjs/text/bitmaptextdata.js +199 -0
- package/dist/melonjs.mjs/text/glyph.js +66 -0
- package/dist/melonjs.mjs/text/text.js +453 -0
- package/dist/melonjs.mjs/text/textmetrics.js +176 -0
- package/dist/melonjs.mjs/text/textstyle.js +23 -0
- package/dist/melonjs.mjs/tweens/easing.js +336 -0
- package/dist/melonjs.mjs/tweens/interpolation.js +112 -0
- package/dist/melonjs.mjs/tweens/tween.js +480 -0
- package/dist/melonjs.mjs/utils/agent.js +76 -0
- package/dist/melonjs.mjs/utils/array.js +63 -0
- package/dist/melonjs.mjs/utils/file.js +42 -0
- package/dist/melonjs.mjs/utils/function.js +70 -0
- package/dist/melonjs.mjs/utils/string.js +82 -0
- package/dist/melonjs.mjs/utils/utils.js +173 -0
- package/dist/melonjs.mjs/video/canvas/canvas_renderer.js +807 -0
- package/dist/melonjs.mjs/video/renderer.js +411 -0
- package/dist/melonjs.mjs/video/texture/atlas.js +519 -0
- package/dist/melonjs.mjs/video/texture/cache.js +143 -0
- package/dist/melonjs.mjs/video/texture/canvas_texture.js +144 -0
- package/dist/melonjs.mjs/video/video.js +462 -0
- package/dist/melonjs.mjs/video/webgl/buffer/vertex.js +143 -0
- package/dist/melonjs.mjs/video/webgl/glshader.js +168 -0
- package/dist/melonjs.mjs/video/webgl/shaders/primitive.frag.js +10 -0
- package/dist/melonjs.mjs/video/webgl/shaders/primitive.vert.js +10 -0
- package/dist/melonjs.mjs/video/webgl/shaders/quad.frag.js +10 -0
- package/dist/melonjs.mjs/video/webgl/shaders/quad.vert.js +10 -0
- package/dist/melonjs.mjs/video/webgl/utils/attributes.js +25 -0
- package/dist/melonjs.mjs/video/webgl/utils/precision.js +20 -0
- package/dist/melonjs.mjs/video/webgl/utils/program.js +67 -0
- package/dist/melonjs.mjs/video/webgl/utils/string.js +25 -0
- package/dist/melonjs.mjs/video/webgl/utils/uniforms.js +92 -0
- package/dist/melonjs.mjs/video/webgl/webgl_compositor.js +495 -0
- package/dist/melonjs.mjs/video/webgl/webgl_renderer.js +1036 -0
- package/dist/melonjs.module.d.ts +1163 -1163
- package/dist/melonjs.module.js +1903 -3274
- package/package.json +22 -17
- package/src/application/application.js +3 -3
- package/src/audio/audio.js +32 -32
- package/src/camera/camera2d.js +31 -31
- package/src/entity/entity.js +17 -17
- package/src/geometries/ellipse.js +16 -16
- package/src/geometries/line.js +5 -5
- package/src/geometries/path2d.js +32 -32
- package/src/geometries/poly.js +15 -15
- package/src/geometries/rectangle.js +18 -18
- package/src/geometries/roundrect.js +8 -8
- package/src/input/gamepad.js +15 -15
- package/src/input/keyboard.js +12 -12
- package/src/input/pointer.js +6 -6
- package/src/input/pointerevent.js +12 -12
- package/src/lang/deprecated.js +12 -12
- package/src/level/level.js +25 -25
- package/src/level/tiled/TMXLayer.js +22 -22
- package/src/level/tiled/TMXTile.js +5 -5
- package/src/level/tiled/TMXTileMap.js +6 -6
- package/src/level/tiled/TMXTileset.js +2 -2
- package/src/level/tiled/TMXUtils.js +5 -5
- package/src/level/tiled/renderer/TMXHexagonalRenderer.js +2 -2
- package/src/level/tiled/renderer/TMXIsometricRenderer.js +2 -2
- package/src/level/tiled/renderer/TMXOrthogonalRenderer.js +1 -1
- package/src/level/tiled/renderer/TMXRenderer.js +19 -19
- package/src/loader/loader.js +20 -20
- package/src/math/color.js +20 -20
- package/src/math/math.js +16 -16
- package/src/math/matrix2.js +16 -16
- package/src/math/matrix3.js +25 -25
- package/src/math/observable_vector2.js +14 -14
- package/src/math/observable_vector3.js +16 -16
- package/src/math/vector2.js +9 -9
- package/src/math/vector3.js +10 -10
- package/src/particles/emitter.js +6 -6
- package/src/particles/particle.js +2 -2
- package/src/physics/body.js +28 -28
- package/src/physics/bounds.js +8 -8
- package/src/physics/collision.js +2 -2
- package/src/physics/detector.js +6 -6
- package/src/physics/quadtree.js +11 -11
- package/src/physics/sat.js +31 -31
- package/src/physics/world.js +5 -5
- package/src/plugin/plugin.js +5 -5
- package/src/renderable/collectable.js +3 -3
- package/src/renderable/colorlayer.js +5 -5
- package/src/renderable/container.js +21 -21
- package/src/renderable/dragndrop.js +14 -14
- package/src/renderable/imagelayer.js +13 -13
- package/src/renderable/light2d.js +3 -3
- package/src/renderable/nineslicesprite.js +16 -16
- package/src/renderable/renderable.js +23 -23
- package/src/renderable/sprite.js +28 -28
- package/src/renderable/trigger.js +15 -15
- package/src/renderable/ui/uibaseelement.js +7 -7
- package/src/renderable/ui/uispriteelement.js +6 -6
- package/src/renderable/ui/uitextbutton.js +13 -13
- package/src/state/stage.js +7 -7
- package/src/state/state.js +17 -17
- package/src/system/device.js +11 -11
- package/src/system/event.js +10 -10
- package/src/system/pooling.js +9 -9
- package/src/system/save.js +2 -2
- package/src/system/timer.js +10 -10
- package/src/text/bitmaptext.js +18 -18
- package/src/text/bitmaptextdata.js +2 -2
- package/src/text/text.js +23 -23
- package/src/text/textmetrics.js +8 -8
- package/src/tweens/tween.js +19 -19
- package/src/utils/agent.js +5 -5
- package/src/utils/array.js +4 -4
- package/src/utils/file.js +2 -2
- package/src/utils/function.js +6 -6
- package/src/utils/string.js +5 -5
- package/src/utils/utils.js +4 -4
- package/src/video/canvas/canvas_renderer.js +70 -70
- package/src/video/renderer.js +26 -26
- package/src/video/texture/atlas.js +22 -22
- package/src/video/texture/canvas_texture.js +9 -9
- package/src/video/video.js +17 -17
- package/src/video/webgl/glshader.js +10 -10
- package/src/video/webgl/webgl_compositor.js +41 -41
- package/src/video/webgl/webgl_renderer.js +75 -75
|
@@ -0,0 +1,480 @@
|
|
|
1
|
+
/*!
|
|
2
|
+
* melonJS Game Engine - v14.1.0
|
|
3
|
+
* http://www.melonjs.org
|
|
4
|
+
* melonjs is licensed under the MIT License.
|
|
5
|
+
* http://www.opensource.org/licenses/mit-license
|
|
6
|
+
* @copyright (C) 2011 - 2022 Olivier Biot (AltByte Pte Ltd)
|
|
7
|
+
*/
|
|
8
|
+
import timer from '../system/timer.js';
|
|
9
|
+
import { on, STATE_RESUME, off } from '../system/event.js';
|
|
10
|
+
import game from '../game.js';
|
|
11
|
+
import { Easing } from './easing.js';
|
|
12
|
+
import { Interpolation } from './interpolation.js';
|
|
13
|
+
|
|
14
|
+
/*
|
|
15
|
+
* Tween.js - Licensed under the MIT license
|
|
16
|
+
* https://github.com/tweenjs/tween.js
|
|
17
|
+
*/
|
|
18
|
+
|
|
19
|
+
/**
|
|
20
|
+
* @classdesc
|
|
21
|
+
* Javascript Tweening Engine<p>
|
|
22
|
+
* Super simple, fast and easy to use tweening engine which incorporates optimised Robert Penner's equation<p>
|
|
23
|
+
* <a href="https://github.com/sole/Tween.js">https://github.com/sole/Tween.js</a><p>
|
|
24
|
+
* author sole / http://soledadpenades.com<br>
|
|
25
|
+
* author mr.doob / http://mrdoob.com<br>
|
|
26
|
+
* author Robert Eisele / http://www.xarg.org<br>
|
|
27
|
+
* author Philippe / http://philippe.elsass.me<br>
|
|
28
|
+
* author Robert Penner / http://www.robertpenner.com/easing_terms_of_use.html<br>
|
|
29
|
+
* author Paul Lewis / http://www.aerotwist.com/<br>
|
|
30
|
+
* author lechecacharro<br>
|
|
31
|
+
* author Josh Faul / http://jocafa.com/
|
|
32
|
+
*/
|
|
33
|
+
class Tween {
|
|
34
|
+
|
|
35
|
+
/**
|
|
36
|
+
* @param {object} object - object on which to apply the tween
|
|
37
|
+
* @example
|
|
38
|
+
* // add a tween to change the object pos.x and pos.y variable to 200 in 3 seconds
|
|
39
|
+
* tween = new me.Tween(myObject.pos).to({
|
|
40
|
+
* x: 200,
|
|
41
|
+
* y: 200,
|
|
42
|
+
* }, {
|
|
43
|
+
* duration: 3000,
|
|
44
|
+
* easing: me.Tween.Easing.Bounce.Out,
|
|
45
|
+
* autoStart : true
|
|
46
|
+
* }).onComplete(myFunc);
|
|
47
|
+
*/
|
|
48
|
+
constructor ( object ) {
|
|
49
|
+
this.setProperties(object);
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
/**
|
|
53
|
+
* reset the tween object to default value
|
|
54
|
+
* @ignore
|
|
55
|
+
*/
|
|
56
|
+
onResetEvent( object ) {
|
|
57
|
+
this.setProperties(object);
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
/**
|
|
61
|
+
* @ignore
|
|
62
|
+
*/
|
|
63
|
+
setProperties(object) {
|
|
64
|
+
this._object = object;
|
|
65
|
+
this._valuesStart = {};
|
|
66
|
+
this._valuesEnd = {};
|
|
67
|
+
this._valuesStartRepeat = {};
|
|
68
|
+
this._duration = 1000;
|
|
69
|
+
this._repeat = 0;
|
|
70
|
+
this._yoyo = false;
|
|
71
|
+
this._reversed = false;
|
|
72
|
+
this._delayTime = 0;
|
|
73
|
+
this._startTime = null;
|
|
74
|
+
this._easingFunction = Easing.Linear.None;
|
|
75
|
+
this._interpolationFunction = Interpolation.Linear;
|
|
76
|
+
this._chainedTweens = [];
|
|
77
|
+
this._onStartCallback = null;
|
|
78
|
+
this._onStartCallbackFired = false;
|
|
79
|
+
this._onUpdateCallback = null;
|
|
80
|
+
this._onCompleteCallback = null;
|
|
81
|
+
// tweens are synchronized with the game update loop
|
|
82
|
+
this._tweenTimeTracker = game.lastUpdate;
|
|
83
|
+
|
|
84
|
+
// reset flags to default value
|
|
85
|
+
this.isPersistent = false;
|
|
86
|
+
// this is not really supported
|
|
87
|
+
this.updateWhenPaused = false;
|
|
88
|
+
// comply with the container contract
|
|
89
|
+
this.isRenderable = false;
|
|
90
|
+
|
|
91
|
+
// Set all starting values present on the target object
|
|
92
|
+
for ( var field in object ) {
|
|
93
|
+
if (typeof object !== "object") {
|
|
94
|
+
this._valuesStart[ field ] = parseFloat(object[field]);
|
|
95
|
+
}
|
|
96
|
+
}
|
|
97
|
+
}
|
|
98
|
+
|
|
99
|
+
/**
|
|
100
|
+
* @ignore
|
|
101
|
+
*/
|
|
102
|
+
_resumeCallback(elapsed) {
|
|
103
|
+
if (this._startTime) {
|
|
104
|
+
this._startTime += elapsed;
|
|
105
|
+
}
|
|
106
|
+
}
|
|
107
|
+
|
|
108
|
+
|
|
109
|
+
|
|
110
|
+
/**
|
|
111
|
+
* subscribe to the resume event when added
|
|
112
|
+
* @ignore
|
|
113
|
+
*/
|
|
114
|
+
onActivateEvent() {
|
|
115
|
+
on(STATE_RESUME, this._resumeCallback, this);
|
|
116
|
+
}
|
|
117
|
+
|
|
118
|
+
/**
|
|
119
|
+
* Unsubscribe when tween is removed
|
|
120
|
+
* @ignore
|
|
121
|
+
*/
|
|
122
|
+
onDeactivateEvent() {
|
|
123
|
+
off(STATE_RESUME, this._resumeCallback);
|
|
124
|
+
}
|
|
125
|
+
|
|
126
|
+
/**
|
|
127
|
+
* object properties to be updated and duration
|
|
128
|
+
* @name to
|
|
129
|
+
* @memberof Tween
|
|
130
|
+
* @public
|
|
131
|
+
* @param {object} properties - hash of properties
|
|
132
|
+
* @param {object|number} [options] - object of tween properties, or a duration if a numeric value is passed
|
|
133
|
+
* @param {number} [options.duration] - tween duration
|
|
134
|
+
* @param {Tween.Easing} [options.easing] - easing function
|
|
135
|
+
* @param {number} [options.delay] - delay amount expressed in milliseconds
|
|
136
|
+
* @param {boolean} [options.yoyo] - allows the tween to bounce back to their original value when finished. To be used together with repeat to create endless loops.
|
|
137
|
+
* @param {number} [options.repeat] - amount of times the tween should be repeated
|
|
138
|
+
* @param {Tween.Interpolation} [options.interpolation] - interpolation function
|
|
139
|
+
* @param {boolean} [options.autoStart] - allow this tween to start automatically. Otherwise call me.Tween.start().
|
|
140
|
+
* @returns {Tween} this instance for object chaining
|
|
141
|
+
*/
|
|
142
|
+
to( properties, options ) {
|
|
143
|
+
|
|
144
|
+
this._valuesEnd = properties;
|
|
145
|
+
|
|
146
|
+
if (typeof options !== "undefined") {
|
|
147
|
+
if (typeof options === "number") {
|
|
148
|
+
// for backward compatiblity
|
|
149
|
+
this._duration = options;
|
|
150
|
+
} else if (typeof options === "object") {
|
|
151
|
+
if (options.duration) { this._duration = options.duration; }
|
|
152
|
+
if (options.yoyo) { this.yoyo(options.yoyo); }
|
|
153
|
+
if (options.easing) { this.easing(options.easing); }
|
|
154
|
+
if (options.repeat) { this.repeat(options.repeat); }
|
|
155
|
+
if (options.delay) { this.delay(options.delay); }
|
|
156
|
+
if (options.interpolation) { this.interpolation(options.interpolation); }
|
|
157
|
+
|
|
158
|
+
if (options.autoStart) {
|
|
159
|
+
this.start();
|
|
160
|
+
}
|
|
161
|
+
}
|
|
162
|
+
}
|
|
163
|
+
|
|
164
|
+
return this;
|
|
165
|
+
}
|
|
166
|
+
|
|
167
|
+
/**
|
|
168
|
+
* start the tween
|
|
169
|
+
* @name start
|
|
170
|
+
* @memberof Tween
|
|
171
|
+
* @public
|
|
172
|
+
* @param {number} [time] - the current time when the tween was started
|
|
173
|
+
* @returns {Tween} this instance for object chaining
|
|
174
|
+
*/
|
|
175
|
+
start( time = timer.getTime() ) {
|
|
176
|
+
|
|
177
|
+
this._onStartCallbackFired = false;
|
|
178
|
+
|
|
179
|
+
// add the tween to the object pool on start
|
|
180
|
+
game.world.addChild(this);
|
|
181
|
+
|
|
182
|
+
this._startTime = time + this._delayTime;
|
|
183
|
+
|
|
184
|
+
for ( var property in this._valuesEnd ) {
|
|
185
|
+
|
|
186
|
+
// check if an Array was provided as property value
|
|
187
|
+
if ( this._valuesEnd[ property ] instanceof Array ) {
|
|
188
|
+
|
|
189
|
+
if ( this._valuesEnd[ property ].length === 0 ) {
|
|
190
|
+
|
|
191
|
+
continue;
|
|
192
|
+
|
|
193
|
+
}
|
|
194
|
+
|
|
195
|
+
// create a local copy of the Array with the start value at the front
|
|
196
|
+
this._valuesEnd[ property ] = [ this._object[ property ] ].concat( this._valuesEnd[ property ] );
|
|
197
|
+
|
|
198
|
+
}
|
|
199
|
+
|
|
200
|
+
this._valuesStart[ property ] = this._object[ property ];
|
|
201
|
+
|
|
202
|
+
if ( ( this._valuesStart[ property ] instanceof Array ) === false ) {
|
|
203
|
+
this._valuesStart[ property ] *= 1.0; // Ensures we're using numbers, not strings
|
|
204
|
+
}
|
|
205
|
+
|
|
206
|
+
this._valuesStartRepeat[ property ] = this._valuesStart[ property ] || 0;
|
|
207
|
+
|
|
208
|
+
}
|
|
209
|
+
|
|
210
|
+
return this;
|
|
211
|
+
}
|
|
212
|
+
|
|
213
|
+
/**
|
|
214
|
+
* stop the tween
|
|
215
|
+
* @name stop
|
|
216
|
+
* @memberof Tween
|
|
217
|
+
* @public
|
|
218
|
+
* @returns {Tween} this instance for object chaining
|
|
219
|
+
*/
|
|
220
|
+
stop() {
|
|
221
|
+
// remove the tween from the world container
|
|
222
|
+
game.world.removeChildNow(this);
|
|
223
|
+
return this;
|
|
224
|
+
}
|
|
225
|
+
|
|
226
|
+
/**
|
|
227
|
+
* delay the tween
|
|
228
|
+
* @name delay
|
|
229
|
+
* @memberof Tween
|
|
230
|
+
* @public
|
|
231
|
+
* @param {number} amount - delay amount expressed in milliseconds
|
|
232
|
+
* @returns {Tween} this instance for object chaining
|
|
233
|
+
*/
|
|
234
|
+
delay( amount ) {
|
|
235
|
+
|
|
236
|
+
this._delayTime = amount;
|
|
237
|
+
return this;
|
|
238
|
+
|
|
239
|
+
}
|
|
240
|
+
|
|
241
|
+
/**
|
|
242
|
+
* Repeat the tween
|
|
243
|
+
* @name repeat
|
|
244
|
+
* @memberof Tween
|
|
245
|
+
* @public
|
|
246
|
+
* @param {number} times - amount of times the tween should be repeated
|
|
247
|
+
* @returns {Tween} this instance for object chaining
|
|
248
|
+
*/
|
|
249
|
+
repeat( times ) {
|
|
250
|
+
|
|
251
|
+
this._repeat = times;
|
|
252
|
+
return this;
|
|
253
|
+
|
|
254
|
+
}
|
|
255
|
+
|
|
256
|
+
/**
|
|
257
|
+
* Allows the tween to bounce back to their original value when finished.
|
|
258
|
+
* To be used together with repeat to create endless loops.
|
|
259
|
+
* @name yoyo
|
|
260
|
+
* @memberof Tween
|
|
261
|
+
* @public
|
|
262
|
+
* @see Tween#repeat
|
|
263
|
+
* @param {boolean} yoyo
|
|
264
|
+
* @returns {Tween} this instance for object chaining
|
|
265
|
+
*/
|
|
266
|
+
yoyo( yoyo ) {
|
|
267
|
+
|
|
268
|
+
this._yoyo = yoyo;
|
|
269
|
+
return this;
|
|
270
|
+
|
|
271
|
+
}
|
|
272
|
+
|
|
273
|
+
/**
|
|
274
|
+
* set the easing function
|
|
275
|
+
* @name easing
|
|
276
|
+
* @memberof Tween
|
|
277
|
+
* @public
|
|
278
|
+
* @param {Tween.Easing} easing - easing function
|
|
279
|
+
* @returns {Tween} this instance for object chaining
|
|
280
|
+
*/
|
|
281
|
+
easing( easing ) {
|
|
282
|
+
if (typeof easing !== "function") {
|
|
283
|
+
throw new Error("invalid easing function for me.Tween.easing()");
|
|
284
|
+
}
|
|
285
|
+
this._easingFunction = easing;
|
|
286
|
+
return this;
|
|
287
|
+
}
|
|
288
|
+
|
|
289
|
+
/**
|
|
290
|
+
* set the interpolation function
|
|
291
|
+
* @name interpolation
|
|
292
|
+
* @memberof Tween
|
|
293
|
+
* @public
|
|
294
|
+
* @param {Tween.Interpolation} interpolation - interpolation function
|
|
295
|
+
* @returns {Tween} this instance for object chaining
|
|
296
|
+
*/
|
|
297
|
+
interpolation( interpolation ) {
|
|
298
|
+
this._interpolationFunction = interpolation;
|
|
299
|
+
return this;
|
|
300
|
+
}
|
|
301
|
+
|
|
302
|
+
/**
|
|
303
|
+
* chain the tween
|
|
304
|
+
* @name chain
|
|
305
|
+
* @memberof Tween
|
|
306
|
+
* @public
|
|
307
|
+
* @param {...Tween} chainedTween - Tween(s) to be chained
|
|
308
|
+
* @returns {Tween} this instance for object chaining
|
|
309
|
+
*/
|
|
310
|
+
chain() {
|
|
311
|
+
this._chainedTweens = arguments;
|
|
312
|
+
return this;
|
|
313
|
+
}
|
|
314
|
+
|
|
315
|
+
/**
|
|
316
|
+
* onStart callback
|
|
317
|
+
* @name onStart
|
|
318
|
+
* @memberof Tween
|
|
319
|
+
* @public
|
|
320
|
+
* @param {Function} onStartCallback - callback
|
|
321
|
+
* @returns {Tween} this instance for object chaining
|
|
322
|
+
*/
|
|
323
|
+
onStart( onStartCallback ) {
|
|
324
|
+
this._onStartCallback = onStartCallback;
|
|
325
|
+
return this;
|
|
326
|
+
}
|
|
327
|
+
|
|
328
|
+
/**
|
|
329
|
+
* onUpdate callback
|
|
330
|
+
* @name onUpdate
|
|
331
|
+
* @memberof Tween
|
|
332
|
+
* @public
|
|
333
|
+
* @param {Function} onUpdateCallback - callback
|
|
334
|
+
* @returns {Tween} this instance for object chaining
|
|
335
|
+
*/
|
|
336
|
+
onUpdate( onUpdateCallback ) {
|
|
337
|
+
this._onUpdateCallback = onUpdateCallback;
|
|
338
|
+
return this;
|
|
339
|
+
}
|
|
340
|
+
|
|
341
|
+
/**
|
|
342
|
+
* onComplete callback
|
|
343
|
+
* @name onComplete
|
|
344
|
+
* @memberof Tween
|
|
345
|
+
* @public
|
|
346
|
+
* @param {Function} onCompleteCallback - callback
|
|
347
|
+
* @returns {Tween} this instance for object chaining
|
|
348
|
+
*/
|
|
349
|
+
onComplete( onCompleteCallback ) {
|
|
350
|
+
this._onCompleteCallback = onCompleteCallback;
|
|
351
|
+
return this;
|
|
352
|
+
}
|
|
353
|
+
|
|
354
|
+
/** @ignore */
|
|
355
|
+
update( dt ) {
|
|
356
|
+
|
|
357
|
+
// the original Tween implementation expect
|
|
358
|
+
// a timestamp and not a time delta
|
|
359
|
+
this._tweenTimeTracker = (game.lastUpdate > this._tweenTimeTracker) ? game.lastUpdate : this._tweenTimeTracker + dt;
|
|
360
|
+
var time = this._tweenTimeTracker;
|
|
361
|
+
|
|
362
|
+
var property;
|
|
363
|
+
|
|
364
|
+
if ( time < this._startTime ) {
|
|
365
|
+
|
|
366
|
+
return true;
|
|
367
|
+
|
|
368
|
+
}
|
|
369
|
+
|
|
370
|
+
if ( this._onStartCallbackFired === false ) {
|
|
371
|
+
|
|
372
|
+
if ( this._onStartCallback !== null ) {
|
|
373
|
+
|
|
374
|
+
this._onStartCallback.call( this._object );
|
|
375
|
+
|
|
376
|
+
}
|
|
377
|
+
|
|
378
|
+
this._onStartCallbackFired = true;
|
|
379
|
+
|
|
380
|
+
}
|
|
381
|
+
|
|
382
|
+
var elapsed = ( time - this._startTime ) / this._duration;
|
|
383
|
+
elapsed = elapsed > 1 ? 1 : elapsed;
|
|
384
|
+
|
|
385
|
+
var value = this._easingFunction( elapsed );
|
|
386
|
+
|
|
387
|
+
for ( property in this._valuesEnd ) {
|
|
388
|
+
|
|
389
|
+
var start = this._valuesStart[ property ] || 0;
|
|
390
|
+
var end = this._valuesEnd[ property ];
|
|
391
|
+
|
|
392
|
+
if ( end instanceof Array ) {
|
|
393
|
+
|
|
394
|
+
this._object[ property ] = this._interpolationFunction( end, value );
|
|
395
|
+
|
|
396
|
+
} else {
|
|
397
|
+
|
|
398
|
+
// Parses relative end values with start as base (e.g.: +10, -3)
|
|
399
|
+
if ( typeof(end) === "string" ) {
|
|
400
|
+
end = start + parseFloat(end);
|
|
401
|
+
}
|
|
402
|
+
|
|
403
|
+
// protect against non numeric properties.
|
|
404
|
+
if ( typeof(end) === "number" ) {
|
|
405
|
+
this._object[ property ] = start + ( end - start ) * value;
|
|
406
|
+
}
|
|
407
|
+
|
|
408
|
+
}
|
|
409
|
+
|
|
410
|
+
}
|
|
411
|
+
|
|
412
|
+
if ( this._onUpdateCallback !== null ) {
|
|
413
|
+
|
|
414
|
+
this._onUpdateCallback.call( this._object, value );
|
|
415
|
+
|
|
416
|
+
}
|
|
417
|
+
|
|
418
|
+
if ( elapsed === 1 ) {
|
|
419
|
+
|
|
420
|
+
if ( this._repeat > 0 ) {
|
|
421
|
+
|
|
422
|
+
if ( isFinite( this._repeat ) ) {
|
|
423
|
+
this._repeat--;
|
|
424
|
+
}
|
|
425
|
+
|
|
426
|
+
// reassign starting values, restart by making startTime = now
|
|
427
|
+
for ( property in this._valuesStartRepeat ) {
|
|
428
|
+
|
|
429
|
+
if ( typeof( this._valuesEnd[ property ] ) === "string" ) {
|
|
430
|
+
this._valuesStartRepeat[ property ] = this._valuesStartRepeat[ property ] + parseFloat(this._valuesEnd[ property ]);
|
|
431
|
+
}
|
|
432
|
+
|
|
433
|
+
if (this._yoyo) {
|
|
434
|
+
var tmp = this._valuesStartRepeat[ property ];
|
|
435
|
+
this._valuesStartRepeat[ property ] = this._valuesEnd[ property ];
|
|
436
|
+
this._valuesEnd[ property ] = tmp;
|
|
437
|
+
}
|
|
438
|
+
this._valuesStart[ property ] = this._valuesStartRepeat[ property ];
|
|
439
|
+
|
|
440
|
+
}
|
|
441
|
+
|
|
442
|
+
if (this._yoyo) {
|
|
443
|
+
this._reversed = !this._reversed;
|
|
444
|
+
}
|
|
445
|
+
|
|
446
|
+
this._startTime = time + this._delayTime;
|
|
447
|
+
|
|
448
|
+
return true;
|
|
449
|
+
|
|
450
|
+
} else {
|
|
451
|
+
// remove the tween from the world container
|
|
452
|
+
game.world.removeChildNow(this);
|
|
453
|
+
|
|
454
|
+
if ( this._onCompleteCallback !== null ) {
|
|
455
|
+
|
|
456
|
+
this._onCompleteCallback.call( this._object );
|
|
457
|
+
|
|
458
|
+
}
|
|
459
|
+
|
|
460
|
+
for ( var i = 0, numChainedTweens = this._chainedTweens.length; i < numChainedTweens; i ++ ) {
|
|
461
|
+
|
|
462
|
+
this._chainedTweens[ i ].start( time );
|
|
463
|
+
|
|
464
|
+
}
|
|
465
|
+
|
|
466
|
+
return false;
|
|
467
|
+
|
|
468
|
+
}
|
|
469
|
+
|
|
470
|
+
}
|
|
471
|
+
return true;
|
|
472
|
+
}
|
|
473
|
+
|
|
474
|
+
// export easing function as static class property
|
|
475
|
+
static get Easing() { return Easing; }
|
|
476
|
+
static get Interpolation() { return Interpolation; }
|
|
477
|
+
}
|
|
478
|
+
var Tween$1 = Tween;
|
|
479
|
+
|
|
480
|
+
export { Tween$1 as default };
|
|
@@ -0,0 +1,76 @@
|
|
|
1
|
+
/*!
|
|
2
|
+
* melonJS Game Engine - v14.1.0
|
|
3
|
+
* http://www.melonjs.org
|
|
4
|
+
* melonjs is licensed under the MIT License.
|
|
5
|
+
* http://www.opensource.org/licenses/mit-license
|
|
6
|
+
* @copyright (C) 2011 - 2022 Olivier Biot (AltByte Pte Ltd)
|
|
7
|
+
*/
|
|
8
|
+
import { capitalize } from './string.js';
|
|
9
|
+
|
|
10
|
+
/**
|
|
11
|
+
* a collection of utility functons to ease porting between different user agents.
|
|
12
|
+
* @namespace utils.agent
|
|
13
|
+
*/
|
|
14
|
+
|
|
15
|
+
/**
|
|
16
|
+
* Known agent vendors
|
|
17
|
+
* @ignore
|
|
18
|
+
*/
|
|
19
|
+
const vendors = [ "ms", "MS", "moz", "webkit", "o" ];
|
|
20
|
+
|
|
21
|
+
/**
|
|
22
|
+
* Get a vendor-prefixed property
|
|
23
|
+
* @public
|
|
24
|
+
* @name prefixed
|
|
25
|
+
* @param {string} name - Property name
|
|
26
|
+
* @param {object} [obj=globalThis] - Object or element reference to access
|
|
27
|
+
* @returns {string} Value of property
|
|
28
|
+
* @memberof utils.agent
|
|
29
|
+
*/
|
|
30
|
+
function prefixed(name, obj) {
|
|
31
|
+
obj = obj || globalThis;
|
|
32
|
+
if (name in obj) {
|
|
33
|
+
return obj[name];
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
var uc_name = capitalize(name);
|
|
37
|
+
|
|
38
|
+
var result;
|
|
39
|
+
vendors.some((vendor) => {
|
|
40
|
+
var name = vendor + uc_name;
|
|
41
|
+
return (result = (name in obj) ? obj[name] : undefined);
|
|
42
|
+
});
|
|
43
|
+
return result;
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
/**
|
|
47
|
+
* Set a vendor-prefixed property
|
|
48
|
+
* @public
|
|
49
|
+
* @name setPrefixed
|
|
50
|
+
* @param {string} name - Property name
|
|
51
|
+
* @param {string} value - Property value
|
|
52
|
+
* @param {object} [obj=globalThis] - Object or element reference to access
|
|
53
|
+
* @returns {boolean} true if one of the vendor-prefixed property was found
|
|
54
|
+
* @memberof utils.agent
|
|
55
|
+
*/
|
|
56
|
+
function setPrefixed(name, value, obj) {
|
|
57
|
+
obj = obj || globalThis;
|
|
58
|
+
if (name in obj) {
|
|
59
|
+
obj[name] = value;
|
|
60
|
+
return;
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
var uc_name = capitalize(name);
|
|
64
|
+
|
|
65
|
+
vendors.some((vendor) => {
|
|
66
|
+
var name = vendor + uc_name;
|
|
67
|
+
if (name in obj) {
|
|
68
|
+
obj[name] = value;
|
|
69
|
+
return true;
|
|
70
|
+
}
|
|
71
|
+
});
|
|
72
|
+
|
|
73
|
+
return false;
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
export { prefixed, setPrefixed };
|
|
@@ -0,0 +1,63 @@
|
|
|
1
|
+
/*!
|
|
2
|
+
* melonJS Game Engine - v14.1.0
|
|
3
|
+
* http://www.melonjs.org
|
|
4
|
+
* melonjs is licensed under the MIT License.
|
|
5
|
+
* http://www.opensource.org/licenses/mit-license
|
|
6
|
+
* @copyright (C) 2011 - 2022 Olivier Biot (AltByte Pte Ltd)
|
|
7
|
+
*/
|
|
8
|
+
import { random as random$1, weightedRandom as weightedRandom$1 } from '../math/math.js';
|
|
9
|
+
|
|
10
|
+
/**
|
|
11
|
+
* a collection of array utility functions
|
|
12
|
+
* @namespace utils.array
|
|
13
|
+
*/
|
|
14
|
+
|
|
15
|
+
/**
|
|
16
|
+
* Remove the specified object from the given Array
|
|
17
|
+
* @public
|
|
18
|
+
* @memberof utils.array
|
|
19
|
+
* @name remove
|
|
20
|
+
* @param {Array} arr - array from which to remove an object
|
|
21
|
+
* @param {object} obj - to be removed
|
|
22
|
+
* @returns {Array} the modified Array
|
|
23
|
+
* var arr = [ "foo", "bar", "baz" ];
|
|
24
|
+
* // remove "foo" from the array
|
|
25
|
+
* me.utils.array.remove(arr, "foo");
|
|
26
|
+
*/
|
|
27
|
+
function remove(arr, obj) {
|
|
28
|
+
var i = Array.prototype.indexOf.call(arr, obj);
|
|
29
|
+
if (i !== -1) {
|
|
30
|
+
Array.prototype.splice.call(arr, i, 1);
|
|
31
|
+
}
|
|
32
|
+
return arr;
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
/**
|
|
36
|
+
* return a random array element
|
|
37
|
+
* @public
|
|
38
|
+
* @memberof utils.array
|
|
39
|
+
* @name random
|
|
40
|
+
* @param {Array} arr - array to pick a element
|
|
41
|
+
* @returns {any} random member of array
|
|
42
|
+
* @example
|
|
43
|
+
* // Select a random array element
|
|
44
|
+
* var arr = [ "foo", "bar", "baz" ];
|
|
45
|
+
* console.log(me.utils.array.random(arr));
|
|
46
|
+
*/
|
|
47
|
+
function random(arr) {
|
|
48
|
+
return arr[random$1(0, arr.length)];
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
/**
|
|
52
|
+
* return a weighted random array element, favoring the earlier entries
|
|
53
|
+
* @public
|
|
54
|
+
* @memberof utils.array
|
|
55
|
+
* @name weightedRandom
|
|
56
|
+
* @param {Array} arr - array to pick a element
|
|
57
|
+
* @returns {any} random member of array
|
|
58
|
+
*/
|
|
59
|
+
function weightedRandom(arr) {
|
|
60
|
+
return arr[weightedRandom$1(0, arr.length)];
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
export { random, remove, weightedRandom };
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
/*!
|
|
2
|
+
* melonJS Game Engine - v14.1.0
|
|
3
|
+
* http://www.melonjs.org
|
|
4
|
+
* melonjs is licensed under the MIT License.
|
|
5
|
+
* http://www.opensource.org/licenses/mit-license
|
|
6
|
+
* @copyright (C) 2011 - 2022 Olivier Biot (AltByte Pte Ltd)
|
|
7
|
+
*/
|
|
8
|
+
/**
|
|
9
|
+
* a collection of file utility functions
|
|
10
|
+
* @namespace utils.file
|
|
11
|
+
*/
|
|
12
|
+
|
|
13
|
+
// regexp to deal with file name & path
|
|
14
|
+
const REMOVE_PATH = /^.*(\\|\/|\:)/;
|
|
15
|
+
const REMOVE_EXT = /\.[^\.]*$/;
|
|
16
|
+
|
|
17
|
+
|
|
18
|
+
/**
|
|
19
|
+
* return the base name of the file without path info
|
|
20
|
+
* @public
|
|
21
|
+
* @memberof utils.file
|
|
22
|
+
* @name getBasename
|
|
23
|
+
* @param {string} path- - path containing the filename
|
|
24
|
+
* @returns {string} the base name without path information.
|
|
25
|
+
*/
|
|
26
|
+
function getBasename(path) {
|
|
27
|
+
return path.replace(REMOVE_PATH, "").replace(REMOVE_EXT, "");
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
/**
|
|
31
|
+
* return the extension of the file in the given path
|
|
32
|
+
* @public
|
|
33
|
+
* @memberof utils.file
|
|
34
|
+
* @name getExtension
|
|
35
|
+
* @param {string} path- - path containing the filename
|
|
36
|
+
* @returns {string} filename extension.
|
|
37
|
+
*/
|
|
38
|
+
function getExtension(path) {
|
|
39
|
+
return path.substring(path.lastIndexOf(".") + 1, path.length);
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
export { getBasename, getExtension };
|