melonjs 10.1.0 → 10.2.2
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 -12
- package/dist/melonjs.js +3119 -2857
- package/dist/melonjs.min.js +3 -3
- package/dist/melonjs.module.d.ts +2590 -2490
- package/dist/melonjs.module.js +2698 -2470
- package/package.json +10 -11
- package/src/audio/audio.js +43 -43
- package/src/camera/camera2d.js +55 -77
- package/src/entity/draggable.js +18 -17
- package/src/entity/droptarget.js +19 -18
- package/src/entity/entity.js +22 -26
- package/src/game.js +3 -3
- package/src/index.js +15 -11
- package/src/input/gamepad.js +13 -13
- package/src/input/input.js +1 -1
- package/src/input/keyboard.js +14 -16
- package/src/input/pointer.js +42 -35
- package/src/input/pointerevent.js +25 -33
- package/src/lang/deprecated.js +3 -3
- package/src/level/level.js +24 -16
- package/src/level/tiled/TMXGroup.js +6 -6
- package/src/level/tiled/TMXLayer.js +31 -31
- package/src/level/tiled/TMXObject.js +19 -19
- package/src/level/tiled/TMXTile.js +11 -12
- package/src/level/tiled/TMXTileMap.js +23 -21
- package/src/level/tiled/TMXTileset.js +13 -13
- package/src/level/tiled/TMXTilesetGroup.js +4 -4
- package/src/level/tiled/TMXUtils.js +13 -11
- package/src/level/tiled/renderer/TMXHexagonalRenderer.js +1 -1
- package/src/level/tiled/renderer/TMXIsometricRenderer.js +1 -1
- package/src/level/tiled/renderer/TMXRenderer.js +17 -17
- package/src/loader/loader.js +31 -27
- package/src/loader/loadingscreen.js +40 -72
- package/src/math/color.js +45 -64
- package/src/math/math.js +17 -17
- package/src/math/matrix2.js +46 -46
- package/src/math/matrix3.js +64 -64
- package/src/math/observable_vector2.js +45 -57
- package/src/math/observable_vector3.js +56 -70
- package/src/math/vector2.js +60 -59
- package/src/math/vector3.js +65 -64
- package/src/particles/emitter.js +53 -55
- package/src/particles/particle.js +1 -1
- package/src/physics/body.js +45 -51
- package/src/physics/bounds.js +36 -36
- package/src/physics/collision.js +15 -16
- package/src/physics/detector.js +10 -11
- package/src/physics/quadtree.js +19 -17
- package/src/physics/sat.js +17 -17
- package/src/physics/world.js +13 -10
- package/src/plugin/plugin.js +6 -6
- package/src/renderable/GUI.js +13 -18
- package/src/renderable/collectable.js +3 -3
- package/src/renderable/colorlayer.js +4 -4
- package/src/renderable/container.js +65 -46
- package/src/renderable/imagelayer.js +32 -31
- package/src/renderable/nineslicesprite.js +211 -0
- package/src/renderable/renderable.js +69 -67
- package/src/renderable/sprite.js +57 -43
- package/src/renderable/trigger.js +14 -15
- package/src/shapes/ellipse.js +27 -26
- package/src/shapes/line.js +8 -7
- package/src/shapes/poly.js +33 -31
- package/src/shapes/rectangle.js +50 -96
- package/src/state/stage.js +8 -8
- package/src/state/state.js +56 -56
- package/src/system/device.js +97 -84
- package/src/system/event.js +72 -72
- package/src/system/pooling.js +14 -14
- package/src/system/save.js +6 -3
- package/src/system/timer.js +20 -20
- package/src/text/bitmaptext.js +27 -33
- package/src/text/bitmaptextdata.js +9 -9
- package/src/text/text.js +118 -59
- package/src/tweens/easing.js +4 -4
- package/src/tweens/interpolation.js +4 -4
- package/src/tweens/tween.js +37 -27
- package/src/utils/agent.js +9 -8
- package/src/utils/array.js +4 -4
- package/src/utils/file.js +4 -4
- package/src/utils/function.js +5 -5
- package/src/utils/string.js +12 -12
- package/src/utils/utils.js +19 -19
- package/src/video/canvas/canvas_renderer.js +90 -90
- package/src/video/renderer.js +40 -39
- package/src/video/texture.js +85 -76
- package/src/video/texture_cache.js +11 -0
- package/src/video/video.js +30 -30
- package/src/video/webgl/buffer/vertex.js +9 -1
- package/src/video/webgl/glshader.js +20 -20
- package/src/video/webgl/webgl_compositor.js +47 -37
- package/src/video/webgl/webgl_renderer.js +104 -104
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "melonjs",
|
|
3
|
-
"version": "10.
|
|
3
|
+
"version": "10.2.2",
|
|
4
4
|
"description": "melonJS Game Engine",
|
|
5
5
|
"homepage": "http://www.melonjs.org/",
|
|
6
6
|
"keywords": [
|
|
@@ -60,26 +60,26 @@
|
|
|
60
60
|
"devDependencies": {
|
|
61
61
|
"@rollup/plugin-buble": "^0.21.3",
|
|
62
62
|
"@rollup/plugin-commonjs": "^21.0.1",
|
|
63
|
-
"@rollup/plugin-node-resolve": "^13.
|
|
63
|
+
"@rollup/plugin-node-resolve": "^13.1.1",
|
|
64
64
|
"@rollup/plugin-replace": "^3.0.0",
|
|
65
65
|
"cheerio": "^1.0.0-rc.10",
|
|
66
66
|
"del-cli": "^4.0.1",
|
|
67
|
-
"eslint": "^8.1
|
|
68
|
-
"
|
|
67
|
+
"eslint": "^8.4.1",
|
|
68
|
+
"eslint-plugin-jsdoc": "^37.2.0",
|
|
69
69
|
"jasmine-core": "^3.10.1",
|
|
70
70
|
"jsdoc": "^3.6.7",
|
|
71
|
-
"karma": "^6.3.
|
|
71
|
+
"karma": "^6.3.9",
|
|
72
72
|
"karma-chrome-launcher": "^3.1.0",
|
|
73
|
-
"karma-coverage": "^2.0
|
|
73
|
+
"karma-coverage": "^2.1.0",
|
|
74
74
|
"karma-html-detailed-reporter": "^2.1.0",
|
|
75
75
|
"karma-jasmine": "^4.0.1",
|
|
76
76
|
"karma-nyan-reporter": "0.2.5",
|
|
77
|
-
"qs": "^6.10.
|
|
78
|
-
"rollup": "^2.
|
|
77
|
+
"qs": "^6.10.2",
|
|
78
|
+
"rollup": "^2.61.1",
|
|
79
79
|
"rollup-plugin-bundle-size": "^1.0.3",
|
|
80
80
|
"rollup-plugin-string": "^3.0.0",
|
|
81
|
-
"terser": "^5.
|
|
82
|
-
"typescript": "^4.
|
|
81
|
+
"terser": "^5.10.0",
|
|
82
|
+
"typescript": "^4.5.4"
|
|
83
83
|
},
|
|
84
84
|
"scripts": {
|
|
85
85
|
"build": "npm run lint && rollup -c --silent",
|
|
@@ -88,7 +88,6 @@
|
|
|
88
88
|
"lint": "eslint --config .eslintrc.json src",
|
|
89
89
|
"test": "npm run build && karma start tests/karma.conf.js",
|
|
90
90
|
"doc": "mkdirp docs && jsdoc -c jsdoc_conf.json",
|
|
91
|
-
"publishdoc": "npm run doc && ghpages melonjs/melonJS -p docs",
|
|
92
91
|
"release": "npm run dist && npm publish --access public",
|
|
93
92
|
"clean": "del-cli --force build/*.js docs src/**/*.d.ts",
|
|
94
93
|
"makedts": "npx -p typescript tsc dist/melonjs.module.js --declaration --allowJs --emitDeclarationOnly",
|
package/src/audio/audio.js
CHANGED
|
@@ -68,7 +68,7 @@ var soundLoadError = function (sound_name, onerror_cb) {
|
|
|
68
68
|
* if false, melonJS will disable sounds and output a warning message
|
|
69
69
|
* in the console<br>
|
|
70
70
|
* @name stopOnAudioError
|
|
71
|
-
* @type {
|
|
71
|
+
* @type {boolean}
|
|
72
72
|
* @default true
|
|
73
73
|
* @memberOf me.audio
|
|
74
74
|
*/
|
|
@@ -84,8 +84,8 @@ export let stopOnAudioError = true;
|
|
|
84
84
|
* It is important to remember that melonJS selects the first compatible sound based on the list of extensions and given order passed here.
|
|
85
85
|
* So if you want webm to be used before mp3, you need to put the audio format in that order.
|
|
86
86
|
* @function me.audio.init
|
|
87
|
-
* @param {
|
|
88
|
-
* @returns {
|
|
87
|
+
* @param {string} [format="mp3"] audio format to prioritize
|
|
88
|
+
* @returns {boolean} Indicates whether audio initialization was successful
|
|
89
89
|
* @example
|
|
90
90
|
* // initialize the "sound engine", giving "webm" as default desired audio format, and "mp3" as a fallback
|
|
91
91
|
* if (!me.audio.init("webm,mp3")) {
|
|
@@ -103,8 +103,8 @@ export let stopOnAudioError = true;
|
|
|
103
103
|
/**
|
|
104
104
|
* check if the given audio format is supported
|
|
105
105
|
* @function me.audio.hasFormat
|
|
106
|
-
* @param {
|
|
107
|
-
* @returns {
|
|
106
|
+
* @param {string} codec audio format : "mp3", "mpeg", opus", "ogg", "oga", "wav", "aac", "caf", "m4a", "m4b", "mp4", "weba", "webm", "dolby", "flac"
|
|
107
|
+
* @returns {boolean} return true if the given audio format is supported
|
|
108
108
|
*/
|
|
109
109
|
export function hasFormat(codec) {
|
|
110
110
|
return hasAudio() && Howler.codecs(codec);
|
|
@@ -113,7 +113,7 @@ export function hasFormat(codec) {
|
|
|
113
113
|
/**
|
|
114
114
|
* check if audio (HTML5 or WebAudio) is supported
|
|
115
115
|
* @function me.audio.hasAudio
|
|
116
|
-
* @returns {
|
|
116
|
+
* @returns {boolean} return true if audio (HTML5 or WebAudio) is supported
|
|
117
117
|
*/
|
|
118
118
|
export function hasAudio() {
|
|
119
119
|
return !Howler.noAudio;
|
|
@@ -181,11 +181,11 @@ export function load(sound, html5, onload_cb, onerror_cb) {
|
|
|
181
181
|
/**
|
|
182
182
|
* play the specified sound
|
|
183
183
|
* @function me.audio.play
|
|
184
|
-
* @param {
|
|
185
|
-
* @param {
|
|
184
|
+
* @param {string} sound_name audio clip name - case sensitive
|
|
185
|
+
* @param {boolean} [loop=false] loop audio
|
|
186
186
|
* @param {Function} [onend] Function to call when sound instance ends playing.
|
|
187
|
-
* @param {
|
|
188
|
-
* @
|
|
187
|
+
* @param {number} [volume=default] Float specifying volume (0.0 - 1.0 values accepted).
|
|
188
|
+
* @returns {number} the sound instance ID.
|
|
189
189
|
* @example
|
|
190
190
|
* // play the "cling" audio clip
|
|
191
191
|
* me.audio.play("cling");
|
|
@@ -222,11 +222,11 @@ export function play(sound_name, loop = false, onend, volume) {
|
|
|
222
222
|
/**
|
|
223
223
|
* Fade a currently playing sound between two volumee.
|
|
224
224
|
* @function me.audio.fade
|
|
225
|
-
* @param {
|
|
226
|
-
* @param {
|
|
227
|
-
* @param {
|
|
228
|
-
* @param {
|
|
229
|
-
* @param {
|
|
225
|
+
* @param {string} sound_name audio clip name - case sensitive
|
|
226
|
+
* @param {number} from Volume to fade from (0.0 to 1.0).
|
|
227
|
+
* @param {number} to Volume to fade to (0.0 to 1.0).
|
|
228
|
+
* @param {number} duration Time in milliseconds to fade.
|
|
229
|
+
* @param {number} [id] the sound instance ID. If none is passed, all sounds in group will fade.
|
|
230
230
|
*/
|
|
231
231
|
export function fade(sound_name, from, to, duration, id) {
|
|
232
232
|
var sound = audioTracks[sound_name];
|
|
@@ -240,10 +240,10 @@ export function fade(sound_name, from, to, duration, id) {
|
|
|
240
240
|
/**
|
|
241
241
|
* get/set the position of playback for a sound.
|
|
242
242
|
* @function me.audio.seek
|
|
243
|
-
* @param {
|
|
244
|
-
* @param {
|
|
245
|
-
* @param {
|
|
246
|
-
* @
|
|
243
|
+
* @param {string} sound_name audio clip name - case sensitive
|
|
244
|
+
* @param {number} [seek] The position to move current playback to (in seconds).
|
|
245
|
+
* @param {number} [id] the sound instance ID. If none is passed, all sounds in group will changed.
|
|
246
|
+
* @returns {number} return the current seek position (if no extra parameters were given)
|
|
247
247
|
* @example
|
|
248
248
|
* // return the current position of the background music
|
|
249
249
|
* var current_pos = me.audio.seek("dst-gameforest");
|
|
@@ -262,10 +262,10 @@ export function seek(sound_name, ...args) {
|
|
|
262
262
|
/**
|
|
263
263
|
* get or set the rate of playback for a sound.
|
|
264
264
|
* @function me.audio.rate
|
|
265
|
-
* @param {
|
|
266
|
-
* @param {
|
|
267
|
-
* @param {
|
|
268
|
-
* @
|
|
265
|
+
* @param {string} sound_name audio clip name - case sensitive
|
|
266
|
+
* @param {number} [rate] playback rate : 0.5 to 4.0, with 1.0 being normal speed.
|
|
267
|
+
* @param {number} [id] the sound instance ID. If none is passed, all sounds in group will be changed.
|
|
268
|
+
* @returns {number} return the current playback rate (if no extra parameters were given)
|
|
269
269
|
* @example
|
|
270
270
|
* // get the playback rate of the background music
|
|
271
271
|
* var rate = me.audio.rate("dst-gameforest");
|
|
@@ -284,8 +284,8 @@ export function rate(sound_name, ...args) {
|
|
|
284
284
|
/**
|
|
285
285
|
* stop the specified sound on all channels
|
|
286
286
|
* @function me.audio.stop
|
|
287
|
-
* @param {
|
|
288
|
-
* @param {
|
|
287
|
+
* @param {string} [sound_name] audio clip name (case sensitive). If none is passed, all sounds are stopped.
|
|
288
|
+
* @param {number} [id] the sound instance ID. If none is passed, all sounds in group will stop.
|
|
289
289
|
* @example
|
|
290
290
|
* me.audio.stop("cling");
|
|
291
291
|
*/
|
|
@@ -308,8 +308,8 @@ export function stop(sound_name, id) {
|
|
|
308
308
|
* pause the specified sound on all channels<br>
|
|
309
309
|
* this function does not reset the currentTime property
|
|
310
310
|
* @function me.audio.pause
|
|
311
|
-
* @param {
|
|
312
|
-
* @param {
|
|
311
|
+
* @param {string} sound_name audio clip name - case sensitive
|
|
312
|
+
* @param {number} [id] the sound instance ID. If none is passed, all sounds in group will pause.
|
|
313
313
|
* @example
|
|
314
314
|
* me.audio.pause("cling");
|
|
315
315
|
*/
|
|
@@ -325,8 +325,8 @@ export function pause(sound_name, id) {
|
|
|
325
325
|
/**
|
|
326
326
|
* resume the specified sound on all channels<br>
|
|
327
327
|
* @function me.audio.resume
|
|
328
|
-
* @param {
|
|
329
|
-
* @param {
|
|
328
|
+
* @param {string} sound_name audio clip name - case sensitive
|
|
329
|
+
* @param {number} [id] the sound instance ID. If none is passed, all sounds in group will resume.
|
|
330
330
|
* @example
|
|
331
331
|
* // play a audio clip
|
|
332
332
|
* var id = me.audio.play("myClip");
|
|
@@ -351,9 +351,9 @@ export function resume(sound_name, id) {
|
|
|
351
351
|
* this function automatically set the loop property to true<br>
|
|
352
352
|
* and keep track of the current sound being played.
|
|
353
353
|
* @function me.audio.playTrack
|
|
354
|
-
* @param {
|
|
355
|
-
* @param {
|
|
356
|
-
* @
|
|
354
|
+
* @param {string} sound_name audio track name - case sensitive
|
|
355
|
+
* @param {number} [volume=default] Float specifying volume (0.0 - 1.0 values accepted).
|
|
356
|
+
* @returns {number} the sound instance ID.
|
|
357
357
|
* @example
|
|
358
358
|
* me.audio.playTrack("awesome_music");
|
|
359
359
|
*/
|
|
@@ -416,7 +416,7 @@ export function resumeTrack() {
|
|
|
416
416
|
/**
|
|
417
417
|
* returns the current track Id
|
|
418
418
|
* @function me.audio.getCurrentTrack
|
|
419
|
-
* @
|
|
419
|
+
* @returns {string} audio track name
|
|
420
420
|
*/
|
|
421
421
|
export function getCurrentTrack() {
|
|
422
422
|
return current_track_id;
|
|
@@ -425,7 +425,7 @@ export function getCurrentTrack() {
|
|
|
425
425
|
/**
|
|
426
426
|
* set the default global volume
|
|
427
427
|
* @function me.audio.setVolume
|
|
428
|
-
* @param {
|
|
428
|
+
* @param {number} volume Float specifying volume (0.0 - 1.0 values accepted).
|
|
429
429
|
*/
|
|
430
430
|
export function setVolume(volume) {
|
|
431
431
|
Howler.volume(volume);
|
|
@@ -434,7 +434,7 @@ export function setVolume(volume) {
|
|
|
434
434
|
/**
|
|
435
435
|
* get the default global volume
|
|
436
436
|
* @function me.audio.getVolume
|
|
437
|
-
* @returns {
|
|
437
|
+
* @returns {number} current volume value in Float [0.0 - 1.0] .
|
|
438
438
|
*/
|
|
439
439
|
export function getVolume() {
|
|
440
440
|
return Howler.volume();
|
|
@@ -443,9 +443,9 @@ export function getVolume() {
|
|
|
443
443
|
/**
|
|
444
444
|
* mute or unmute the specified sound, but does not pause the playback.
|
|
445
445
|
* @function me.audio.mute
|
|
446
|
-
* @param {
|
|
447
|
-
* @param {
|
|
448
|
-
* @param {
|
|
446
|
+
* @param {string} sound_name audio clip name - case sensitive
|
|
447
|
+
* @param {number} [id] the sound instance ID. If none is passed, all sounds in group will mute.
|
|
448
|
+
* @param {boolean} [mute=true] True to mute and false to unmute
|
|
449
449
|
* @example
|
|
450
450
|
* // mute the background music
|
|
451
451
|
* me.audio.mute("awesome_music");
|
|
@@ -464,8 +464,8 @@ export function mute(sound_name, id, mute) {
|
|
|
464
464
|
/**
|
|
465
465
|
* unmute the specified sound
|
|
466
466
|
* @function me.audio.unmute
|
|
467
|
-
* @param {
|
|
468
|
-
* @param {
|
|
467
|
+
* @param {string} sound_name audio clip name
|
|
468
|
+
* @param {number} [id] the sound instance ID. If none is passed, all sounds in group will unmute.
|
|
469
469
|
*/
|
|
470
470
|
export function unmute(sound_name, id) {
|
|
471
471
|
mute(sound_name, id, false);
|
|
@@ -490,7 +490,7 @@ export function unmuteAll() {
|
|
|
490
490
|
/**
|
|
491
491
|
* Returns true if audio is muted globally.
|
|
492
492
|
* @function me.audio.muted
|
|
493
|
-
* @
|
|
493
|
+
* @returns {boolean} true if audio is muted globally
|
|
494
494
|
*/
|
|
495
495
|
export function muted() {
|
|
496
496
|
return Howler._muted;
|
|
@@ -499,8 +499,8 @@ export function muted() {
|
|
|
499
499
|
/**
|
|
500
500
|
* unload specified audio track to free memory
|
|
501
501
|
* @function me.audio.unload
|
|
502
|
-
* @param {
|
|
503
|
-
* @
|
|
502
|
+
* @param {string} sound_name audio track name - case sensitive
|
|
503
|
+
* @returns {boolean} true if unloaded
|
|
504
504
|
* @example
|
|
505
505
|
* me.audio.unload("awesome_music");
|
|
506
506
|
*/
|
package/src/camera/camera2d.js
CHANGED
|
@@ -25,10 +25,10 @@ var targetV = new Vector2d();
|
|
|
25
25
|
* @extends me.Renderable
|
|
26
26
|
* @memberOf me
|
|
27
27
|
* @constructor
|
|
28
|
-
* @param {
|
|
29
|
-
* @param {
|
|
30
|
-
* @param {
|
|
31
|
-
* @param {
|
|
28
|
+
* @param {number} minX start x offset
|
|
29
|
+
* @param {number} minY start y offset
|
|
30
|
+
* @param {number} maxX end x offset
|
|
31
|
+
* @param {number} maxY end y offset
|
|
32
32
|
*/
|
|
33
33
|
class Camera2d extends Renderable {
|
|
34
34
|
|
|
@@ -40,13 +40,13 @@ class Camera2d extends Renderable {
|
|
|
40
40
|
|
|
41
41
|
/**
|
|
42
42
|
* Axis definition
|
|
43
|
-
* @property NONE
|
|
44
|
-
* @property HORIZONTAL
|
|
45
|
-
* @property VERTICAL
|
|
46
|
-
* @property BOTH
|
|
43
|
+
* @property {number} NONE no axis
|
|
44
|
+
* @property {number} HORIZONTAL horizontal axis only
|
|
45
|
+
* @property {number} VERTICAL vertical axis only
|
|
46
|
+
* @property {number} BOTH both axis
|
|
47
47
|
* @public
|
|
48
48
|
* @constant
|
|
49
|
-
* @enum {
|
|
49
|
+
* @enum {number}
|
|
50
50
|
* @name AXIS
|
|
51
51
|
* @memberOf me.Camera2d
|
|
52
52
|
*/
|
|
@@ -60,7 +60,7 @@ class Camera2d extends Renderable {
|
|
|
60
60
|
/**
|
|
61
61
|
* Camera bounds
|
|
62
62
|
* @public
|
|
63
|
-
* @type me.Bounds
|
|
63
|
+
* @type {me.Bounds}
|
|
64
64
|
* @name bounds
|
|
65
65
|
* @memberOf me.Camera2d
|
|
66
66
|
*/
|
|
@@ -69,7 +69,7 @@ class Camera2d extends Renderable {
|
|
|
69
69
|
/**
|
|
70
70
|
* [IMTERNAL] enable or disable damping
|
|
71
71
|
* @private
|
|
72
|
-
* @type {
|
|
72
|
+
* @type {boolean}
|
|
73
73
|
* @name smoothFollow
|
|
74
74
|
* @see me.Camera2d.damping
|
|
75
75
|
* @default true
|
|
@@ -81,7 +81,7 @@ class Camera2d extends Renderable {
|
|
|
81
81
|
* Camera damping for smooth transition [0 .. 1].
|
|
82
82
|
* 1 being the maximum value and will snap the camera to the target position
|
|
83
83
|
* @public
|
|
84
|
-
* @type {
|
|
84
|
+
* @type {number}
|
|
85
85
|
* @name damping
|
|
86
86
|
* @default 1.0
|
|
87
87
|
* @memberOf me.Camera2d
|
|
@@ -91,7 +91,7 @@ class Camera2d extends Renderable {
|
|
|
91
91
|
/**
|
|
92
92
|
* the closest point relative to the camera
|
|
93
93
|
* @public
|
|
94
|
-
* @type {
|
|
94
|
+
* @type {number}
|
|
95
95
|
* @name near
|
|
96
96
|
* @default -1000
|
|
97
97
|
* @memberOf me.Camera2d
|
|
@@ -101,7 +101,7 @@ class Camera2d extends Renderable {
|
|
|
101
101
|
/**
|
|
102
102
|
* the furthest point relative to the camera.
|
|
103
103
|
* @public
|
|
104
|
-
* @type {
|
|
104
|
+
* @type {number}
|
|
105
105
|
* @name far
|
|
106
106
|
* @default 1000
|
|
107
107
|
* @memberOf me.Camera2d
|
|
@@ -218,13 +218,13 @@ class Camera2d extends Renderable {
|
|
|
218
218
|
* @name reset
|
|
219
219
|
* @memberOf me.Camera2d
|
|
220
220
|
* @function
|
|
221
|
-
* @param {
|
|
222
|
-
* @param {
|
|
221
|
+
* @param {number} [x=0]
|
|
222
|
+
* @param {number} [y=0]
|
|
223
223
|
*/
|
|
224
|
-
reset(x, y) {
|
|
224
|
+
reset(x = 0, y = 0) {
|
|
225
225
|
// reset the initial camera position to 0,0
|
|
226
|
-
this.pos.x = x
|
|
227
|
-
this.pos.y = y
|
|
226
|
+
this.pos.x = x;
|
|
227
|
+
this.pos.y = y;
|
|
228
228
|
|
|
229
229
|
// reset the target
|
|
230
230
|
this.unfollow();
|
|
@@ -249,8 +249,8 @@ class Camera2d extends Renderable {
|
|
|
249
249
|
* @see me.Camera2d.follow
|
|
250
250
|
* @memberOf me.Camera2d
|
|
251
251
|
* @function
|
|
252
|
-
* @param {
|
|
253
|
-
* @param {
|
|
252
|
+
* @param {number} w deadzone width
|
|
253
|
+
* @param {number} h deadzone height
|
|
254
254
|
*/
|
|
255
255
|
setDeadzone(w, h) {
|
|
256
256
|
if (typeof(this.deadzone) === "undefined") {
|
|
@@ -277,10 +277,10 @@ class Camera2d extends Renderable {
|
|
|
277
277
|
* @name resize
|
|
278
278
|
* @memberOf me.Camera2d
|
|
279
279
|
* @function
|
|
280
|
-
* @param {
|
|
281
|
-
* @param {
|
|
282
|
-
* @
|
|
283
|
-
|
|
280
|
+
* @param {number} w new width of the camera
|
|
281
|
+
* @param {number} h new height of the camera
|
|
282
|
+
* @returns {me.Camera2d} this camera
|
|
283
|
+
*/
|
|
284
284
|
resize(w, h) {
|
|
285
285
|
// parent consctructor, resize camera rect
|
|
286
286
|
super.resize(w, h);
|
|
@@ -309,10 +309,10 @@ class Camera2d extends Renderable {
|
|
|
309
309
|
* @name setBounds
|
|
310
310
|
* @memberOf me.Camera2d
|
|
311
311
|
* @function
|
|
312
|
-
* @param {
|
|
313
|
-
* @param {
|
|
314
|
-
* @param {
|
|
315
|
-
* @param {
|
|
312
|
+
* @param {number} x world left limit
|
|
313
|
+
* @param {number} y world top limit
|
|
314
|
+
* @param {number} w world width limit
|
|
315
|
+
* @param {number} h world height limit
|
|
316
316
|
*/
|
|
317
317
|
setBounds(x, y, w, h) {
|
|
318
318
|
this.smoothFollow = false;
|
|
@@ -330,7 +330,7 @@ class Camera2d extends Renderable {
|
|
|
330
330
|
* @function
|
|
331
331
|
* @param {me.Renderable|me.Vector2d} target renderable or position vector to follow
|
|
332
332
|
* @param {me.Camera2d.AXIS} [axis=this.AXIS.BOTH] Which axis to follow
|
|
333
|
-
* @param {
|
|
333
|
+
* @param {number} [damping=1] default damping value
|
|
334
334
|
* @example
|
|
335
335
|
* // set the camera to follow this renderable on both axis, and enable damping
|
|
336
336
|
* me.game.viewport.follow(this, me.game.viewport.AXIS.BOTH, 0.1);
|
|
@@ -382,8 +382,8 @@ class Camera2d extends Renderable {
|
|
|
382
382
|
* @memberOf me.Camera2d
|
|
383
383
|
* @see me.Camera2d.focusOn
|
|
384
384
|
* @function
|
|
385
|
-
* @param {
|
|
386
|
-
* @param {
|
|
385
|
+
* @param {number} x
|
|
386
|
+
* @param {number} y
|
|
387
387
|
* @example
|
|
388
388
|
* // Move the camera up by four pixels
|
|
389
389
|
* me.game.viewport.move(0, -4);
|
|
@@ -398,8 +398,8 @@ class Camera2d extends Renderable {
|
|
|
398
398
|
* @memberOf me.Camera2d
|
|
399
399
|
* @see me.Camera2d.focusOn
|
|
400
400
|
* @function
|
|
401
|
-
* @param {
|
|
402
|
-
* @param {
|
|
401
|
+
* @param {number} x
|
|
402
|
+
* @param {number} y
|
|
403
403
|
*/
|
|
404
404
|
moveTo(x, y) {
|
|
405
405
|
var _x = this.pos.x;
|
|
@@ -521,13 +521,13 @@ class Camera2d extends Renderable {
|
|
|
521
521
|
* @name shake
|
|
522
522
|
* @memberOf me.Camera2d
|
|
523
523
|
* @function
|
|
524
|
-
* @param {
|
|
524
|
+
* @param {number} intensity maximum offset that the screen can be moved
|
|
525
525
|
* while shaking
|
|
526
|
-
* @param {
|
|
526
|
+
* @param {number} duration expressed in milliseconds
|
|
527
527
|
* @param {me.Camera2d.AXIS} [axis=this.AXIS.BOTH] specify on which axis you
|
|
528
528
|
* want the shake effect
|
|
529
529
|
* @param {Function} [onComplete] callback once shaking effect is over
|
|
530
|
-
* @param {
|
|
530
|
+
* @param {boolean} [force] if true this will override the current effect
|
|
531
531
|
* @example
|
|
532
532
|
* // shake it baby !
|
|
533
533
|
* me.game.viewport.shake(10, 500, me.game.viewport.AXIS.BOTH);
|
|
@@ -547,8 +547,8 @@ class Camera2d extends Renderable {
|
|
|
547
547
|
* @name fadeOut
|
|
548
548
|
* @memberOf me.Camera2d
|
|
549
549
|
* @function
|
|
550
|
-
* @param {me.Color|
|
|
551
|
-
* @param {
|
|
550
|
+
* @param {me.Color|string} color a CSS color value
|
|
551
|
+
* @param {number} [duration=1000] expressed in milliseconds
|
|
552
552
|
* @param {Function} [onComplete] callback once effect is over
|
|
553
553
|
* @example
|
|
554
554
|
* // fade the camera to white upon dying, reload the level, and then fade out back
|
|
@@ -573,8 +573,8 @@ class Camera2d extends Renderable {
|
|
|
573
573
|
* @name fadeIn
|
|
574
574
|
* @memberOf me.Camera2d
|
|
575
575
|
* @function
|
|
576
|
-
* @param {me.Color|
|
|
577
|
-
* @param {
|
|
576
|
+
* @param {me.Color|string} color a CSS color value
|
|
577
|
+
* @param {number} [duration=1000] expressed in milliseconds
|
|
578
578
|
* @param {Function} [onComplete] callback once effect is over
|
|
579
579
|
* @example
|
|
580
580
|
* // flash the camera to white for 75ms
|
|
@@ -591,34 +591,12 @@ class Camera2d extends Renderable {
|
|
|
591
591
|
this._fadeIn.tween.start();
|
|
592
592
|
}
|
|
593
593
|
|
|
594
|
-
/**
|
|
595
|
-
* return the camera width
|
|
596
|
-
* @name getWidth
|
|
597
|
-
* @memberOf me.Camera2d
|
|
598
|
-
* @function
|
|
599
|
-
* @return {Number}
|
|
600
|
-
*/
|
|
601
|
-
getWidth() {
|
|
602
|
-
return this.width;
|
|
603
|
-
}
|
|
604
|
-
|
|
605
|
-
/**
|
|
606
|
-
* return the camera height
|
|
607
|
-
* @name getHeight
|
|
608
|
-
* @memberOf me.Camera2d
|
|
609
|
-
* @function
|
|
610
|
-
* @return {Number}
|
|
611
|
-
*/
|
|
612
|
-
getHeight() {
|
|
613
|
-
return this.height;
|
|
614
|
-
}
|
|
615
|
-
|
|
616
594
|
/**
|
|
617
595
|
* set the camera position around the specified object
|
|
618
596
|
* @name focusOn
|
|
619
597
|
* @memberOf me.Camera2d
|
|
620
598
|
* @function
|
|
621
|
-
* @param {me.Renderable}
|
|
599
|
+
* @param {me.Renderable} target the renderable to focus the camera on
|
|
622
600
|
*/
|
|
623
601
|
focusOn(target) {
|
|
624
602
|
var bounds = target.getBounds();
|
|
@@ -633,9 +611,9 @@ class Camera2d extends Renderable {
|
|
|
633
611
|
* @name isVisible
|
|
634
612
|
* @memberOf me.Camera2d
|
|
635
613
|
* @function
|
|
636
|
-
* @param {me.Renderable}
|
|
637
|
-
* @param {
|
|
638
|
-
* @
|
|
614
|
+
* @param {me.Renderable} obj to be checked against
|
|
615
|
+
* @param {boolean} [floating = obj.floating] if visibility check should be done against screen coordinates
|
|
616
|
+
* @returns {boolean}
|
|
639
617
|
*/
|
|
640
618
|
isVisible(obj, floating = obj.floating) {
|
|
641
619
|
if (floating === true || obj.floating === true) {
|
|
@@ -652,15 +630,15 @@ class Camera2d extends Renderable {
|
|
|
652
630
|
* @name localToWorld
|
|
653
631
|
* @memberOf me.Camera2d
|
|
654
632
|
* @function
|
|
655
|
-
* @param {
|
|
656
|
-
* @param {
|
|
657
|
-
* @param {
|
|
633
|
+
* @param {number} x
|
|
634
|
+
* @param {number} y
|
|
635
|
+
* @param {number} [v] an optional vector object where to set the
|
|
658
636
|
* converted value
|
|
659
|
-
* @
|
|
637
|
+
* @returns {me.Vector2d}
|
|
660
638
|
*/
|
|
661
639
|
localToWorld(x, y, v) {
|
|
662
640
|
// TODO memoization for one set of coords (multitouch)
|
|
663
|
-
v = v ||
|
|
641
|
+
v = v || pool.pull("Vector2d");
|
|
664
642
|
v.set(x, y).add(this.pos).sub(world.pos);
|
|
665
643
|
if (!this.currentTransform.isIdentity()) {
|
|
666
644
|
this.invCurrentTransform.apply(v);
|
|
@@ -673,15 +651,15 @@ class Camera2d extends Renderable {
|
|
|
673
651
|
* @name worldToLocal
|
|
674
652
|
* @memberOf me.Camera2d
|
|
675
653
|
* @function
|
|
676
|
-
* @param {
|
|
677
|
-
* @param {
|
|
678
|
-
* @param {
|
|
654
|
+
* @param {number} x
|
|
655
|
+
* @param {number} y
|
|
656
|
+
* @param {number} [v] an optional vector object where to set the
|
|
679
657
|
* converted value
|
|
680
|
-
* @
|
|
658
|
+
* @returns {me.Vector2d}
|
|
681
659
|
*/
|
|
682
660
|
worldToLocal(x, y, v) {
|
|
683
661
|
// TODO memoization for one set of coords (multitouch)
|
|
684
|
-
v = v ||
|
|
662
|
+
v = v || pool.pull("Vector2d");
|
|
685
663
|
v.set(x, y);
|
|
686
664
|
if (!this.currentTransform.isIdentity()) {
|
|
687
665
|
this.currentTransform.apply(v);
|
package/src/entity/draggable.js
CHANGED
|
@@ -4,15 +4,15 @@ import * as event from "./../system/event.js";
|
|
|
4
4
|
import Entity from "./entity.js";
|
|
5
5
|
|
|
6
6
|
/**
|
|
7
|
-
* Used to make a game entity draggable
|
|
8
|
-
* @class
|
|
9
|
-
* @extends me.Entity
|
|
10
|
-
* @memberOf me
|
|
11
|
-
* @constructor
|
|
12
|
-
* @param {
|
|
13
|
-
* @param {
|
|
14
|
-
* @param {
|
|
15
|
-
*/
|
|
7
|
+
* Used to make a game entity draggable
|
|
8
|
+
* @class
|
|
9
|
+
* @extends me.Entity
|
|
10
|
+
* @memberOf me
|
|
11
|
+
* @constructor
|
|
12
|
+
* @param {number} x the x coordinates of the entity object
|
|
13
|
+
* @param {number} y the y coordinates of the entity object
|
|
14
|
+
* @param {object} settings Entity properties (see {@link me.Entity})
|
|
15
|
+
*/
|
|
16
16
|
class DraggableEntity extends Entity {
|
|
17
17
|
|
|
18
18
|
/**
|
|
@@ -20,9 +20,9 @@ class DraggableEntity extends Entity {
|
|
|
20
20
|
* @name init
|
|
21
21
|
* @memberOf me.DraggableEntity
|
|
22
22
|
* @function
|
|
23
|
-
* @param {
|
|
24
|
-
* @param {
|
|
25
|
-
* @param {
|
|
23
|
+
* @param {number} x the x postion of the entity
|
|
24
|
+
* @param {number} y the y postion of the entity
|
|
25
|
+
* @param {object} settings the additional entity settings
|
|
26
26
|
*/
|
|
27
27
|
constructor(x, y, settings) {
|
|
28
28
|
super(x, y, settings);
|
|
@@ -70,8 +70,8 @@ class DraggableEntity extends Entity {
|
|
|
70
70
|
* @name translatePointerEvent
|
|
71
71
|
* @memberOf me.DraggableEntity
|
|
72
72
|
* @function
|
|
73
|
-
* @param {
|
|
74
|
-
* @param {
|
|
73
|
+
* @param {object} e the pointer event you want to translate
|
|
74
|
+
* @param {string} translation the me.event you want to translate the event to
|
|
75
75
|
*/
|
|
76
76
|
translatePointerEvent(e, translation) {
|
|
77
77
|
event.emit(translation, e);
|
|
@@ -82,7 +82,8 @@ class DraggableEntity extends Entity {
|
|
|
82
82
|
* @name dragStart
|
|
83
83
|
* @memberOf me.DraggableEntity
|
|
84
84
|
* @function
|
|
85
|
-
* @param {
|
|
85
|
+
* @param {object} e the pointer event
|
|
86
|
+
* @returns {boolean} false if the object is being dragged
|
|
86
87
|
*/
|
|
87
88
|
dragStart(e) {
|
|
88
89
|
if (this.dragging === false) {
|
|
@@ -98,7 +99,7 @@ class DraggableEntity extends Entity {
|
|
|
98
99
|
* @name dragMove
|
|
99
100
|
* @memberOf me.DraggableEntity
|
|
100
101
|
* @function
|
|
101
|
-
* @param {
|
|
102
|
+
* @param {object} e the pointer event
|
|
102
103
|
*/
|
|
103
104
|
dragMove(e) {
|
|
104
105
|
if (this.dragging === true) {
|
|
@@ -112,7 +113,7 @@ class DraggableEntity extends Entity {
|
|
|
112
113
|
* @name dragEnd
|
|
113
114
|
* @memberOf me.DraggableEntity
|
|
114
115
|
* @function
|
|
115
|
-
* @
|
|
116
|
+
* @returns {boolean} false if the object stopped being dragged
|
|
116
117
|
*/
|
|
117
118
|
dragEnd() {
|
|
118
119
|
if (this.dragging === true) {
|