melonjs 16.0.0 → 16.1.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/README.md +1 -0
- package/dist/melonjs.mjs/_virtual/_commonjsHelpers.js +1 -1
- package/dist/melonjs.mjs/_virtual/earcut.js +1 -1
- package/dist/melonjs.mjs/_virtual/howler.js +1 -1
- package/dist/melonjs.mjs/_virtual/index.js +1 -1
- package/dist/melonjs.mjs/application/application.js +1 -1
- package/dist/melonjs.mjs/application/header.js +1 -1
- package/dist/melonjs.mjs/application/resize.js +1 -1
- package/dist/melonjs.mjs/application/settings.js +1 -1
- package/dist/melonjs.mjs/audio/audio.js +4 -2
- package/dist/melonjs.mjs/camera/camera2d.js +1 -1
- package/dist/melonjs.mjs/const.js +1 -1
- package/dist/melonjs.mjs/geometries/ellipse.js +1 -1
- package/dist/melonjs.mjs/geometries/line.js +1 -1
- package/dist/melonjs.mjs/geometries/path2d.js +1 -1
- package/dist/melonjs.mjs/geometries/point.js +1 -1
- package/dist/melonjs.mjs/geometries/poly.js +1 -1
- package/dist/melonjs.mjs/geometries/rectangle.js +1 -1
- package/dist/melonjs.mjs/geometries/roundrect.js +1 -1
- package/dist/melonjs.mjs/geometries/toarccanvas.js +1 -1
- package/dist/melonjs.mjs/index.js +2 -2
- package/dist/melonjs.mjs/input/gamepad.js +1 -1
- package/dist/melonjs.mjs/input/input.js +1 -1
- package/dist/melonjs.mjs/input/keyboard.js +1 -1
- package/dist/melonjs.mjs/input/pointer.js +1 -1
- package/dist/melonjs.mjs/input/pointerevent.js +1 -1
- package/dist/melonjs.mjs/lang/console.js +1 -1
- package/dist/melonjs.mjs/lang/deprecated.js +1 -1
- package/dist/melonjs.mjs/level/level.js +1 -1
- package/dist/melonjs.mjs/level/tiled/TMXGroup.js +1 -1
- package/dist/melonjs.mjs/level/tiled/TMXLayer.js +1 -1
- package/dist/melonjs.mjs/level/tiled/TMXObject.js +1 -1
- package/dist/melonjs.mjs/level/tiled/TMXTile.js +1 -1
- package/dist/melonjs.mjs/level/tiled/TMXTileMap.js +1 -1
- package/dist/melonjs.mjs/level/tiled/TMXTileset.js +1 -1
- package/dist/melonjs.mjs/level/tiled/TMXTilesetGroup.js +1 -1
- package/dist/melonjs.mjs/level/tiled/TMXUtils.js +1 -1
- package/dist/melonjs.mjs/level/tiled/constants.js +1 -1
- package/dist/melonjs.mjs/level/tiled/renderer/TMXHexagonalRenderer.js +1 -1
- package/dist/melonjs.mjs/level/tiled/renderer/TMXIsometricRenderer.js +1 -1
- package/dist/melonjs.mjs/level/tiled/renderer/TMXOrthogonalRenderer.js +1 -1
- package/dist/melonjs.mjs/level/tiled/renderer/TMXRenderer.js +1 -1
- package/dist/melonjs.mjs/level/tiled/renderer/TMXStaggeredRenderer.js +1 -1
- package/dist/melonjs.mjs/level/tiled/renderer/autodetect.js +1 -1
- package/dist/melonjs.mjs/loader/cache.js +5 -2
- package/dist/melonjs.mjs/loader/loader.js +58 -9
- package/dist/melonjs.mjs/loader/loadingscreen.js +1 -1
- package/dist/melonjs.mjs/loader/melonjs_logo.png.js +1 -1
- package/dist/melonjs.mjs/loader/parsers/binary.js +1 -1
- package/dist/melonjs.mjs/loader/parsers/fetchdata.js +1 -1
- package/dist/melonjs.mjs/loader/parsers/fontface.js +1 -1
- package/dist/melonjs.mjs/loader/parsers/image.js +1 -1
- package/dist/melonjs.mjs/loader/parsers/json.js +1 -1
- package/dist/melonjs.mjs/loader/parsers/script.js +1 -1
- package/dist/melonjs.mjs/loader/parsers/tmx.js +1 -1
- package/dist/melonjs.mjs/loader/parsers/video.js +99 -0
- package/dist/melonjs.mjs/loader/settings.js +5 -4
- package/dist/melonjs.mjs/math/color.js +1 -1
- package/dist/melonjs.mjs/math/math.js +1 -1
- package/dist/melonjs.mjs/math/matrix2.js +1 -1
- package/dist/melonjs.mjs/math/matrix3.js +1 -1
- package/dist/melonjs.mjs/math/observable_vector2.js +1 -1
- package/dist/melonjs.mjs/math/observable_vector3.js +1 -1
- package/dist/melonjs.mjs/math/vector2.js +1 -1
- package/dist/melonjs.mjs/math/vector3.js +1 -1
- package/dist/melonjs.mjs/node_modules/@teppeis/multimaps/dist/esm/arraymultimap.js +1 -1
- package/dist/melonjs.mjs/node_modules/@teppeis/multimaps/dist/esm/multimap.js +1 -1
- package/dist/melonjs.mjs/node_modules/earcut/src/earcut.js +1 -1
- package/dist/melonjs.mjs/node_modules/eventemitter3/index.js +1 -1
- package/dist/melonjs.mjs/node_modules/eventemitter3/index2.js +1 -1
- package/dist/melonjs.mjs/node_modules/howler/dist/howler.js +1 -1
- package/dist/melonjs.mjs/particles/emitter.js +1 -1
- package/dist/melonjs.mjs/particles/particle.js +1 -1
- package/dist/melonjs.mjs/particles/settings.js +1 -1
- package/dist/melonjs.mjs/physics/body.js +1 -1
- package/dist/melonjs.mjs/physics/bounds.js +1 -1
- package/dist/melonjs.mjs/physics/collision.js +1 -1
- package/dist/melonjs.mjs/physics/detector.js +1 -1
- package/dist/melonjs.mjs/physics/quadtree.js +1 -1
- package/dist/melonjs.mjs/physics/response.js +1 -1
- package/dist/melonjs.mjs/physics/sat.js +1 -1
- package/dist/melonjs.mjs/physics/world.js +1 -1
- package/dist/melonjs.mjs/plugin/plugin.js +3 -3
- package/dist/melonjs.mjs/renderable/collectable.js +1 -1
- package/dist/melonjs.mjs/renderable/colorlayer.js +1 -1
- package/dist/melonjs.mjs/renderable/container.js +1 -1
- package/dist/melonjs.mjs/renderable/draggable.js +1 -1
- package/dist/melonjs.mjs/renderable/dragndrop.js +1 -1
- package/dist/melonjs.mjs/renderable/entity/entity.js +1 -1
- package/dist/melonjs.mjs/renderable/imagelayer.js +1 -1
- package/dist/melonjs.mjs/renderable/light2d.js +1 -1
- package/dist/melonjs.mjs/renderable/nineslicesprite.js +1 -5
- package/dist/melonjs.mjs/renderable/renderable.js +1 -1
- package/dist/melonjs.mjs/renderable/sprite.js +135 -80
- package/dist/melonjs.mjs/renderable/text/bitmaptext.js +1 -1
- package/dist/melonjs.mjs/renderable/text/bitmaptextdata.js +1 -1
- package/dist/melonjs.mjs/renderable/text/glyph.js +1 -1
- package/dist/melonjs.mjs/renderable/text/text.js +1 -1
- package/dist/melonjs.mjs/renderable/text/textmetrics.js +1 -1
- package/dist/melonjs.mjs/renderable/text/textstyle.js +1 -1
- package/dist/melonjs.mjs/renderable/trigger.js +1 -1
- package/dist/melonjs.mjs/renderable/ui/uibaseelement.js +1 -1
- package/dist/melonjs.mjs/renderable/ui/uispriteelement.js +1 -1
- package/dist/melonjs.mjs/renderable/ui/uitextbutton.js +1 -1
- package/dist/melonjs.mjs/state/stage.js +1 -1
- package/dist/melonjs.mjs/state/state.js +1 -1
- package/dist/melonjs.mjs/system/device.js +45 -2
- package/dist/melonjs.mjs/system/dom.js +1 -1
- package/dist/melonjs.mjs/system/event.js +1 -1
- package/dist/melonjs.mjs/system/platform.js +1 -1
- package/dist/melonjs.mjs/system/pooling.js +1 -1
- package/dist/melonjs.mjs/system/save.js +1 -1
- package/dist/melonjs.mjs/system/timer.js +1 -1
- package/dist/melonjs.mjs/tweens/easing.js +1 -1
- package/dist/melonjs.mjs/tweens/interpolation.js +1 -1
- package/dist/melonjs.mjs/tweens/tween.js +1 -1
- package/dist/melonjs.mjs/utils/agent.js +1 -1
- package/dist/melonjs.mjs/utils/array.js +1 -1
- package/dist/melonjs.mjs/utils/file.js +1 -1
- package/dist/melonjs.mjs/utils/function.js +1 -1
- package/dist/melonjs.mjs/utils/string.js +1 -1
- package/dist/melonjs.mjs/utils/utils.js +1 -1
- package/dist/melonjs.mjs/video/canvas/canvas_renderer.js +1 -1
- package/dist/melonjs.mjs/video/renderer.js +1 -1
- package/dist/melonjs.mjs/video/texture/atlas.js +1 -1
- package/dist/melonjs.mjs/video/texture/cache.js +4 -4
- package/dist/melonjs.mjs/video/texture/canvas_texture.js +1 -1
- package/dist/melonjs.mjs/video/utils/autodetect.js +1 -1
- package/dist/melonjs.mjs/video/video.js +1 -1
- package/dist/melonjs.mjs/video/webgl/buffer/vertex.js +1 -1
- package/dist/melonjs.mjs/video/webgl/compositors/compositor.js +1 -1
- package/dist/melonjs.mjs/video/webgl/compositors/primitive_compositor.js +1 -1
- package/dist/melonjs.mjs/video/webgl/compositors/quad_compositor.js +4 -3
- package/dist/melonjs.mjs/video/webgl/glshader.js +1 -1
- package/dist/melonjs.mjs/video/webgl/shaders/primitive.frag.js +1 -1
- package/dist/melonjs.mjs/video/webgl/shaders/primitive.vert.js +1 -1
- package/dist/melonjs.mjs/video/webgl/shaders/quad.frag.js +1 -1
- package/dist/melonjs.mjs/video/webgl/shaders/quad.vert.js +1 -1
- package/dist/melonjs.mjs/video/webgl/utils/attributes.js +1 -1
- package/dist/melonjs.mjs/video/webgl/utils/precision.js +1 -1
- package/dist/melonjs.mjs/video/webgl/utils/program.js +1 -1
- package/dist/melonjs.mjs/video/webgl/utils/string.js +1 -1
- package/dist/melonjs.mjs/video/webgl/utils/uniforms.js +1 -1
- package/dist/melonjs.mjs/video/webgl/webgl_renderer.js +4 -3
- package/dist/melonjs.module.js +340 -104
- package/dist/types/loader/cache.d.ts +1 -0
- package/dist/types/loader/loader.d.ts +37 -8
- package/dist/types/loader/parsers/video.d.ts +9 -0
- package/dist/types/loader/settings.d.ts +3 -3
- package/dist/types/renderable/nineslicesprite.d.ts +12 -0
- package/dist/types/renderable/sprite.d.ts +41 -40
- package/dist/types/system/device.d.ts +16 -0
- package/dist/types/video/webgl/compositors/quad_compositor.d.ts +2 -1
- package/package.json +3 -3
- package/src/audio/audio.js +3 -1
- package/src/loader/cache.js +3 -0
- package/src/loader/loader.js +57 -7
- package/src/loader/parsers/video.js +90 -0
- package/src/loader/settings.js +4 -3
- package/src/renderable/nineslicesprite.js +0 -4
- package/src/renderable/sprite.js +134 -79
- package/src/system/device.js +43 -0
- package/src/video/texture/cache.js +3 -3
- package/src/video/webgl/compositors/quad_compositor.js +3 -2
- package/src/video/webgl/webgl_renderer.js +3 -2
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
/*!
|
|
2
|
-
* melonJS Game Engine - v16.
|
|
2
|
+
* melonJS Game Engine - v16.1.1
|
|
3
3
|
* http://www.melonjs.org
|
|
4
4
|
* melonjs is licensed under the MIT License.
|
|
5
5
|
* http://www.opensource.org/licenses/mit-license
|
|
@@ -11,6 +11,7 @@ import { getImage } from '../loader/loader.js';
|
|
|
11
11
|
import { TextureAtlas } from '../video/texture/atlas.js';
|
|
12
12
|
import Renderable from './renderable.js';
|
|
13
13
|
import Color from '../math/color.js';
|
|
14
|
+
import { on, STATE_PAUSE, off } from '../system/event.js';
|
|
14
15
|
|
|
15
16
|
/**
|
|
16
17
|
* @classdesc
|
|
@@ -22,7 +23,7 @@ class Sprite extends Renderable {
|
|
|
22
23
|
* @param {number} x - the x coordinates of the sprite object
|
|
23
24
|
* @param {number} y - the y coordinates of the sprite object
|
|
24
25
|
* @param {object} settings - Configuration parameters for the Sprite object
|
|
25
|
-
* @param {HTMLImageElement|HTMLCanvasElement|TextureAtlas|string} settings.image - reference to spritesheet image, a texture atlas or to a texture atlas
|
|
26
|
+
* @param {HTMLImageElement|HTMLCanvasElement|HTMLVideoElement|TextureAtlas|string} settings.image - reference to spritesheet image, a texture atlas, a video element, or to a texture atlas
|
|
26
27
|
* @param {string} [settings.name=""] - name of this object
|
|
27
28
|
* @param {string} [settings.region] - region name of a specific region to use when using a texture atlas, see {@link TextureAtlas}
|
|
28
29
|
* @param {number} [settings.framewidth] - Width of a single frame within the spritesheet
|
|
@@ -49,6 +50,16 @@ class Sprite extends Renderable {
|
|
|
49
50
|
* image : mytexture,
|
|
50
51
|
* region : "npc2.png",
|
|
51
52
|
* });
|
|
53
|
+
*
|
|
54
|
+
* // create a video sprite
|
|
55
|
+
* let videoSprite = new me.Sprite(0, 0, {
|
|
56
|
+
* image : me.loader.getVideo("bigbunny"),
|
|
57
|
+
* anchorPoint : new me.Vector2d(0.5, 0.5)
|
|
58
|
+
* });
|
|
59
|
+
* // scale the video sprite
|
|
60
|
+
* videoSprite.currentTransform.scale(2);
|
|
61
|
+
* // start playing the video (if video is preloaded with `autoplay` set to false)
|
|
62
|
+
* videoSprite.play();
|
|
52
63
|
*/
|
|
53
64
|
constructor(x, y, settings) {
|
|
54
65
|
|
|
@@ -56,39 +67,42 @@ class Sprite extends Renderable {
|
|
|
56
67
|
super(x, y, 0, 0);
|
|
57
68
|
|
|
58
69
|
/**
|
|
59
|
-
* pause and resume animation
|
|
60
|
-
* @public
|
|
61
70
|
* @type {boolean}
|
|
62
71
|
* @default false
|
|
63
|
-
* @name Sprite#animationpause
|
|
64
72
|
*/
|
|
65
73
|
this.animationpause = false;
|
|
66
74
|
|
|
67
75
|
/**
|
|
68
76
|
* animation cycling speed (delay between frame in ms)
|
|
69
|
-
* @public
|
|
70
77
|
* @type {number}
|
|
71
78
|
* @default 100
|
|
72
|
-
* @name Sprite#animationspeed
|
|
73
79
|
*/
|
|
74
80
|
this.animationspeed = 100;
|
|
75
81
|
|
|
76
82
|
/**
|
|
77
83
|
* global offset for the position to draw from on the source image.
|
|
78
|
-
* @public
|
|
79
84
|
* @type {Vector2d}
|
|
80
85
|
* @default <0.0,0.0>
|
|
81
|
-
* @name offset
|
|
82
|
-
* @memberof Sprite#
|
|
83
86
|
*/
|
|
84
87
|
this.offset = pool.pull("Vector2d", 0, 0);
|
|
85
88
|
|
|
89
|
+
/**
|
|
90
|
+
* true if this is a video sprite (e.g. a HTMLVideoElement was passed as as source)
|
|
91
|
+
* @type {boolean}
|
|
92
|
+
* @default false
|
|
93
|
+
*/
|
|
94
|
+
this.isVideo = false;
|
|
95
|
+
|
|
96
|
+
/**
|
|
97
|
+
* a callback fired when the end of a video or current animation was reached
|
|
98
|
+
* @type {Function}
|
|
99
|
+
* @default undefined
|
|
100
|
+
*/
|
|
101
|
+
this.onended;
|
|
102
|
+
|
|
86
103
|
/**
|
|
87
104
|
* The source texture object this sprite object is using
|
|
88
|
-
* @public
|
|
89
105
|
* @type {TextureAtlas}
|
|
90
|
-
* @name source
|
|
91
|
-
* @memberof Sprite#
|
|
92
106
|
*/
|
|
93
107
|
this.source = null;
|
|
94
108
|
|
|
@@ -106,7 +120,7 @@ class Sprite extends Renderable {
|
|
|
106
120
|
// length of the current animation name
|
|
107
121
|
length : 0,
|
|
108
122
|
//current frame texture offset
|
|
109
|
-
offset : pool.pull("Vector2d"),
|
|
123
|
+
offset : pool.pull("Vector2d", 0, 0),
|
|
110
124
|
// current frame size
|
|
111
125
|
width : 0,
|
|
112
126
|
height : 0,
|
|
@@ -145,17 +159,46 @@ class Sprite extends Renderable {
|
|
|
145
159
|
}
|
|
146
160
|
}
|
|
147
161
|
} else {
|
|
148
|
-
// HTMLImageElement/
|
|
162
|
+
// HTMLImageElement/HTMLVideoElementCanvas or {string}
|
|
149
163
|
this.image = (typeof settings.image === "object") ? settings.image : getImage(settings.image);
|
|
150
164
|
// throw an error if image ends up being null/undefined
|
|
151
165
|
if (!this.image) {
|
|
152
166
|
throw new Error("me.Sprite: '" + settings.image + "' image/texture not found!");
|
|
153
167
|
}
|
|
154
|
-
|
|
155
|
-
this.
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
168
|
+
|
|
169
|
+
this.isVideo = HTMLVideoElement && this.image instanceof HTMLVideoElement;
|
|
170
|
+
|
|
171
|
+
if (this.isVideo) {
|
|
172
|
+
this.width = this.current.width = settings.framewidth = settings.framewidth || this.image.videoWidth;
|
|
173
|
+
this.height = this.current.height = settings.frameheight = settings.frameheight || this.image.videoHeight;
|
|
174
|
+
// video specific parameter
|
|
175
|
+
this.animationpause = this.image.autoplay !== true;
|
|
176
|
+
if (this.animationpause) {
|
|
177
|
+
this.image.pause();
|
|
178
|
+
}
|
|
179
|
+
|
|
180
|
+
// pause the video when losing focus
|
|
181
|
+
this._onBlurFn = () => { this.image.pause(); };
|
|
182
|
+
on(STATE_PAUSE, this._onBlurFn);
|
|
183
|
+
|
|
184
|
+
// call the onended when the video has ended
|
|
185
|
+
this.image.onended = () => {
|
|
186
|
+
if (typeof this.onended === "function") {
|
|
187
|
+
// prevent the video from restarting if video.loop is false
|
|
188
|
+
if (!this.image.loop) {
|
|
189
|
+
this.animationpause = true;
|
|
190
|
+
}
|
|
191
|
+
this.onended();
|
|
192
|
+
}
|
|
193
|
+
};
|
|
194
|
+
|
|
195
|
+
} else {
|
|
196
|
+
// update the default "current" frame size
|
|
197
|
+
this.width = this.current.width = settings.framewidth = settings.framewidth || this.image.width;
|
|
198
|
+
this.height = this.current.height = settings.frameheight = settings.frameheight || this.image.height;
|
|
199
|
+
this.source = renderer.cache.get(this.image, settings);
|
|
200
|
+
this.textureAtlas = this.source.getAtlas();
|
|
201
|
+
}
|
|
159
202
|
}
|
|
160
203
|
|
|
161
204
|
// store/reset the current atlas information if specified
|
|
@@ -203,7 +246,7 @@ class Sprite extends Renderable {
|
|
|
203
246
|
}
|
|
204
247
|
|
|
205
248
|
// addAnimation will return 0 if no texture atlas is defined
|
|
206
|
-
if (this.addAnimation("default", null) !== 0) {
|
|
249
|
+
if (!this.isVideo && this.addAnimation("default", null) !== 0) {
|
|
207
250
|
// set as default
|
|
208
251
|
this.setCurrentAnimation("default");
|
|
209
252
|
}
|
|
@@ -211,18 +254,28 @@ class Sprite extends Renderable {
|
|
|
211
254
|
|
|
212
255
|
/**
|
|
213
256
|
* return the flickering state of the object
|
|
214
|
-
* @name isFlickering
|
|
215
|
-
* @memberof Sprite
|
|
216
257
|
* @returns {boolean}
|
|
217
258
|
*/
|
|
218
259
|
isFlickering() {
|
|
219
260
|
return this._flicker.isFlickering;
|
|
220
261
|
}
|
|
221
262
|
|
|
263
|
+
/**
|
|
264
|
+
* play or resume the current animation or video
|
|
265
|
+
*/
|
|
266
|
+
play() {
|
|
267
|
+
this.animationpause = false;
|
|
268
|
+
}
|
|
269
|
+
|
|
270
|
+
/**
|
|
271
|
+
* play or resume the current animation or video
|
|
272
|
+
*/
|
|
273
|
+
pause() {
|
|
274
|
+
this.animationpause = true;
|
|
275
|
+
}
|
|
276
|
+
|
|
222
277
|
/**
|
|
223
278
|
* make the object flicker
|
|
224
|
-
* @name flicker
|
|
225
|
-
* @memberof Sprite
|
|
226
279
|
* @param {number} duration - expressed in milliseconds
|
|
227
280
|
* @param {Function} callback - Function to call when flickering ends
|
|
228
281
|
* @returns {Sprite} Reference to this object for method chaining
|
|
@@ -251,11 +304,8 @@ class Sprite extends Renderable {
|
|
|
251
304
|
* For fixed-sized cell sprite sheet, the index list must follow the
|
|
252
305
|
* logic as per the following example :<br>
|
|
253
306
|
* <img src="images/spritesheet_grid.png"/>
|
|
254
|
-
* @name addAnimation
|
|
255
|
-
* @memberof Sprite
|
|
256
307
|
* @param {string} name - animation id
|
|
257
|
-
* @param {number[]|string[]|object[]} index - list of sprite index or name
|
|
258
|
-
* defining the animation. Can also use objects to specify delay for each frame, see below
|
|
308
|
+
* @param {number[]|string[]|object[]} index - list of sprite index or name defining the animation. Can also use objects to specify delay for each frame, see below
|
|
259
309
|
* @param {number} [animationspeed] - cycling speed for animation in ms
|
|
260
310
|
* @returns {number} frame amount of frame added to the animation (delay between each frame).
|
|
261
311
|
* @see Sprite#animationspeed
|
|
@@ -350,8 +400,6 @@ class Sprite extends Renderable {
|
|
|
350
400
|
/**
|
|
351
401
|
* set the current animation
|
|
352
402
|
* this will always change the animation & set the frame to zero
|
|
353
|
-
* @name setCurrentAnimation
|
|
354
|
-
* @memberof Sprite
|
|
355
403
|
* @param {string} name - animation id
|
|
356
404
|
* @param {string|Function} [resetAnim] - animation id to switch to when complete, or callback
|
|
357
405
|
* @param {boolean} [preserve_dt=false] - if false will reset the elapsed time counter since last frame
|
|
@@ -412,8 +460,6 @@ class Sprite extends Renderable {
|
|
|
412
460
|
|
|
413
461
|
/**
|
|
414
462
|
* reverse the given or current animation if none is specified
|
|
415
|
-
* @name reverseAnimation
|
|
416
|
-
* @memberof Sprite
|
|
417
463
|
* @param {string} [name] - animation id
|
|
418
464
|
* @returns {Sprite} Reference to this object for method chaining
|
|
419
465
|
* @see Sprite#animationspeed
|
|
@@ -430,8 +476,6 @@ class Sprite extends Renderable {
|
|
|
430
476
|
|
|
431
477
|
/**
|
|
432
478
|
* return true if the specified animation is the current one.
|
|
433
|
-
* @name isCurrentAnimation
|
|
434
|
-
* @memberof Sprite
|
|
435
479
|
* @param {string} name - animation id
|
|
436
480
|
* @returns {boolean}
|
|
437
481
|
* @example
|
|
@@ -446,8 +490,6 @@ class Sprite extends Renderable {
|
|
|
446
490
|
/**
|
|
447
491
|
* change the current texture atlas region for this sprite
|
|
448
492
|
* @see Texture.getRegion
|
|
449
|
-
* @name setRegion
|
|
450
|
-
* @memberof Sprite
|
|
451
493
|
* @param {object} region - typically returned through me.Texture.getRegion()
|
|
452
494
|
* @returns {Sprite} Reference to this object for method chaining
|
|
453
495
|
* @example
|
|
@@ -479,8 +521,6 @@ class Sprite extends Renderable {
|
|
|
479
521
|
|
|
480
522
|
/**
|
|
481
523
|
* force the current animation frame index.
|
|
482
|
-
* @name setAnimationFrame
|
|
483
|
-
* @memberof Sprite
|
|
484
524
|
* @param {number} [index=0] - animation frame index
|
|
485
525
|
* @returns {Sprite} Reference to this object for method chaining
|
|
486
526
|
* @example
|
|
@@ -494,8 +534,6 @@ class Sprite extends Renderable {
|
|
|
494
534
|
|
|
495
535
|
/**
|
|
496
536
|
* return the current animation frame index.
|
|
497
|
-
* @name getCurrentAnimationFrame
|
|
498
|
-
* @memberof Sprite
|
|
499
537
|
* @returns {number} current animation frame index
|
|
500
538
|
*/
|
|
501
539
|
getCurrentAnimationFrame() {
|
|
@@ -504,8 +542,6 @@ class Sprite extends Renderable {
|
|
|
504
542
|
|
|
505
543
|
/**
|
|
506
544
|
* Returns the frame object by the index.
|
|
507
|
-
* @name getAnimationFrameObjectByIndex
|
|
508
|
-
* @memberof Sprite
|
|
509
545
|
* @ignore
|
|
510
546
|
* @param {number} id - the frame id
|
|
511
547
|
* @returns {number} if using number indices. Returns {object} containing frame data if using texture atlas
|
|
@@ -517,38 +553,51 @@ class Sprite extends Renderable {
|
|
|
517
553
|
/**
|
|
518
554
|
* update function. <br>
|
|
519
555
|
* automatically called by the game manager {@link game}
|
|
520
|
-
* @name update
|
|
521
|
-
* @memberof Sprite
|
|
522
556
|
* @protected
|
|
523
557
|
* @param {number} dt - time since the last update in milliseconds.
|
|
524
558
|
* @returns {boolean} true if the Sprite is dirty
|
|
525
559
|
*/
|
|
526
560
|
update(dt) {
|
|
527
|
-
//
|
|
528
|
-
if (
|
|
529
|
-
|
|
530
|
-
|
|
531
|
-
|
|
532
|
-
this.
|
|
533
|
-
|
|
534
|
-
|
|
535
|
-
|
|
536
|
-
|
|
537
|
-
|
|
538
|
-
|
|
539
|
-
|
|
540
|
-
|
|
541
|
-
|
|
542
|
-
|
|
543
|
-
|
|
544
|
-
|
|
545
|
-
|
|
546
|
-
|
|
547
|
-
|
|
561
|
+
// play/pause video if necessary
|
|
562
|
+
if (this.isVideo) {
|
|
563
|
+
if (this.animationpause) {
|
|
564
|
+
this.image.pause();
|
|
565
|
+
} else if (this.image.paused) {
|
|
566
|
+
this.image.play();
|
|
567
|
+
}
|
|
568
|
+
this.isDirty = !this.image.paused;
|
|
569
|
+
} else {
|
|
570
|
+
// Update animation if necessary
|
|
571
|
+
if (!this.animationpause && this.current.length > 1) {
|
|
572
|
+
let duration = this.getAnimationFrameObjectByIndex(this.current.idx).delay;
|
|
573
|
+
this.dt += dt;
|
|
574
|
+
while (this.dt >= duration) {
|
|
575
|
+
this.isDirty = true;
|
|
576
|
+
this.dt -= duration;
|
|
577
|
+
|
|
578
|
+
let nextFrame = (this.current.length > 1 ? this.current.idx + 1 : this.current.idx);
|
|
579
|
+
this.setAnimationFrame(nextFrame);
|
|
580
|
+
|
|
581
|
+
// Switch animation if we reach the end of the strip and a callback is defined
|
|
582
|
+
if (this.current.idx === 0) {
|
|
583
|
+
if (typeof this.onended === "function") {
|
|
584
|
+
this.onended();
|
|
585
|
+
}
|
|
586
|
+
if (typeof this.resetAnim === "function") {
|
|
587
|
+
// Otherwise is must be callable
|
|
588
|
+
if (this.resetAnim() === false) {
|
|
589
|
+
// Reset to last frame
|
|
590
|
+
this.setAnimationFrame(this.current.length - 1);
|
|
591
|
+
|
|
592
|
+
// Bail early without skipping any more frames.
|
|
593
|
+
this.dt %= duration;
|
|
594
|
+
break;
|
|
595
|
+
}
|
|
596
|
+
}
|
|
548
597
|
}
|
|
598
|
+
// Get next frame duration
|
|
599
|
+
duration = this.getAnimationFrameObjectByIndex(this.current.idx).delay;
|
|
549
600
|
}
|
|
550
|
-
// Get next frame duration
|
|
551
|
-
duration = this.getAnimationFrameObjectByIndex(this.current.idx).delay;
|
|
552
601
|
}
|
|
553
602
|
}
|
|
554
603
|
|
|
@@ -567,20 +616,8 @@ class Sprite extends Renderable {
|
|
|
567
616
|
return super.update(dt);
|
|
568
617
|
}
|
|
569
618
|
|
|
570
|
-
/**
|
|
571
|
-
* Destroy function<br>
|
|
572
|
-
* @ignore
|
|
573
|
-
*/
|
|
574
|
-
destroy() {
|
|
575
|
-
pool.push(this.offset);
|
|
576
|
-
this.offset = undefined;
|
|
577
|
-
super.destroy();
|
|
578
|
-
}
|
|
579
|
-
|
|
580
619
|
/**
|
|
581
620
|
* draw this srite (automatically called by melonJS)
|
|
582
|
-
* @name draw
|
|
583
|
-
* @memberof Sprite
|
|
584
621
|
* @protected
|
|
585
622
|
* @param {CanvasRenderer|WebGLRenderer} renderer - a renderer instance
|
|
586
623
|
* @param {Camera2d} [viewport] - the viewport to (re)draw
|
|
@@ -627,6 +664,24 @@ class Sprite extends Renderable {
|
|
|
627
664
|
w, h // dw,dh
|
|
628
665
|
);
|
|
629
666
|
}
|
|
667
|
+
|
|
668
|
+
/**
|
|
669
|
+
* Destroy function<br>
|
|
670
|
+
* @ignore
|
|
671
|
+
*/
|
|
672
|
+
destroy() {
|
|
673
|
+
pool.push(this.offset);
|
|
674
|
+
this.offset = undefined;
|
|
675
|
+
if (this.isVideo) {
|
|
676
|
+
off(STATE_PAUSE, this._onBlurFn);
|
|
677
|
+
this._onBlurFn = undefined;
|
|
678
|
+
this.image.onended = undefined;
|
|
679
|
+
this.image.pause();
|
|
680
|
+
this.image.currentTime = 0;
|
|
681
|
+
}
|
|
682
|
+
this.image = undefined;
|
|
683
|
+
super.destroy();
|
|
684
|
+
}
|
|
630
685
|
}
|
|
631
686
|
|
|
632
687
|
export { Sprite as default };
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
/*!
|
|
2
|
-
* melonJS Game Engine - v16.
|
|
2
|
+
* melonJS Game Engine - v16.1.1
|
|
3
3
|
* http://www.melonjs.org
|
|
4
4
|
* melonjs is licensed under the MIT License.
|
|
5
5
|
* http://www.opensource.org/licenses/mit-license
|
|
@@ -24,6 +24,9 @@ let swipeEnabled = true;
|
|
|
24
24
|
// a cache DOMRect object
|
|
25
25
|
let domRect = {left: 0, top: 0, x: 0, y: 0, width: 0, height: 0, right: 0, bottom: 0};
|
|
26
26
|
|
|
27
|
+
// a list of supported videoCodecs;
|
|
28
|
+
let videoCodecs;
|
|
29
|
+
|
|
27
30
|
function disableSwipeFn(e) {
|
|
28
31
|
e.preventDefault();
|
|
29
32
|
if (typeof globalThis.scroll === "function") {
|
|
@@ -222,6 +225,18 @@ const hasHTML5Audio = (typeof globalThis.Audio !== "undefined");
|
|
|
222
225
|
*/
|
|
223
226
|
const sound = hasWebAudio || hasHTML5Audio;
|
|
224
227
|
|
|
228
|
+
|
|
229
|
+
/**
|
|
230
|
+
* Device Video Support
|
|
231
|
+
* @name hasVideo
|
|
232
|
+
* @memberof device
|
|
233
|
+
* @type {boolean}
|
|
234
|
+
* @readonly
|
|
235
|
+
* @public
|
|
236
|
+
*/
|
|
237
|
+
const hasVideo = typeof globalThis.document !== "undefined" && !!globalThis.document.createElement("video").canPlayType;
|
|
238
|
+
|
|
239
|
+
|
|
225
240
|
/**
|
|
226
241
|
* Browser Local Storage capabilities <br>
|
|
227
242
|
* (this flag will be set to false if cookies are blocked)
|
|
@@ -927,4 +942,32 @@ function vibrate(pattern) {
|
|
|
927
942
|
}
|
|
928
943
|
}
|
|
929
944
|
|
|
930
|
-
|
|
945
|
+
/**
|
|
946
|
+
* detect if the given video format is supported
|
|
947
|
+
* @function hasVideoFormat
|
|
948
|
+
* @param {"h264"|"h265"|"ogg"|"mp4"|"m4v"|"webm"|"vp9"|"hls"} codec - the video format to check for support
|
|
949
|
+
* @returns {boolean} return true if the given video format is supported
|
|
950
|
+
*/
|
|
951
|
+
function hasVideoFormat(codec) {
|
|
952
|
+
let result = false;
|
|
953
|
+
if (hasVideo === true) {
|
|
954
|
+
if (typeof videoCodecs === "undefined") {
|
|
955
|
+
// check for support
|
|
956
|
+
const videoElement = document.createElement("video");
|
|
957
|
+
videoCodecs = {
|
|
958
|
+
h264:videoElement.canPlayType('video/mp4; codecs="avc1.42E01E"').replace(/^no$/, ""),
|
|
959
|
+
h265:videoElement.canPlayType('video/mp4; codecs="hev1"').replace(/^no$/, ""),
|
|
960
|
+
ogg:videoElement.canPlayType('video/ogg; codecs="theora"').replace(/^no$/, ""),
|
|
961
|
+
mp4:videoElement.canPlayType('video/mp4; codecs="avc1.42E01E"').replace(/^no$/, ""),
|
|
962
|
+
m4v:videoElement.canPlayType("video/x-m4v").replace(/^no$/, ""),
|
|
963
|
+
webm:videoElement.canPlayType('video/webm; codecs="vp8, vorbis"').replace(/^no$/, ""),
|
|
964
|
+
vp9:videoElement.canPlayType('video/webm; codecs="vp9"').replace(/^no$/, ""),
|
|
965
|
+
hls:videoElement.canPlayType('application/x-mpegURL; codecs="avc1.42E01E"').replace(/^no$/, "")
|
|
966
|
+
};
|
|
967
|
+
}
|
|
968
|
+
result = !!videoCodecs[codec];
|
|
969
|
+
}
|
|
970
|
+
return result;
|
|
971
|
+
}
|
|
972
|
+
|
|
973
|
+
export { accelerationX, accelerationY, accelerationZ, alpha, autoFocus, beta, devicePixelRatio, enableSwipe, exitFullscreen, focus, gamma, getElement, getElementBounds, getParentBounds, getParentElement, getScreenOrientation, getStorage, hasAccelerometer, hasDeviceOrientation, hasFullscreenSupport, hasHTML5Audio, hasPointerLockSupport, hasVideo, hasVideoFormat, hasWebAudio, isFullscreen, isLandscape, isMobile, isPortrait, isWebGLSupported, language, localStorage, lockOrientation, maxTouchPoints, nativeBase64, offscreenCanvas, onDeviceRotate, onReady, pauseOnBlur, platform, pointerEvent, requestFullscreen, resumeOnFocus, screenOrientation, sound, stopOnBlur, touch, touchEvent, unlockOrientation, unwatchAccelerometer, unwatchDeviceOrientation, vibrate, watchAccelerometer, watchDeviceOrientation, wheel };
|