melonjs 10.1.1 → 10.2.3
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 -10
- package/dist/melonjs.js +3114 -2866
- package/dist/melonjs.min.js +3 -3
- package/dist/melonjs.module.d.ts +2588 -2498
- package/dist/melonjs.module.js +2694 -2479
- package/package.json +10 -11
- package/src/audio/audio.js +43 -43
- package/src/camera/camera2d.js +52 -74
- 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 +44 -75
- 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 +18 -16
- package/src/physics/sat.js +17 -17
- package/src/physics/world.js +12 -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 +64 -46
- package/src/renderable/imagelayer.js +30 -31
- package/src/renderable/nineslicesprite.js +158 -69
- package/src/renderable/renderable.js +68 -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 +31 -31
- 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 -46
- package/src/video/webgl/webgl_renderer.js +104 -104
package/src/entity/droptarget.js
CHANGED
|
@@ -2,15 +2,15 @@ import * as event from "./../system/event.js";
|
|
|
2
2
|
import Entity from "./entity.js";
|
|
3
3
|
|
|
4
4
|
/**
|
|
5
|
-
* Used to make a game entity a droptarget
|
|
6
|
-
* @class
|
|
7
|
-
* @extends me.Entity
|
|
8
|
-
* @memberOf me
|
|
9
|
-
* @constructor
|
|
10
|
-
* @param {
|
|
11
|
-
* @param {
|
|
12
|
-
* @param {
|
|
13
|
-
*/
|
|
5
|
+
* Used to make a game entity a droptarget
|
|
6
|
+
* @class
|
|
7
|
+
* @extends me.Entity
|
|
8
|
+
* @memberOf me
|
|
9
|
+
* @constructor
|
|
10
|
+
* @param {number} x the x coordinates of the entity object
|
|
11
|
+
* @param {number} y the y coordinates of the entity object
|
|
12
|
+
* @param {object} settings Entity properties (see {@link me.Entity})
|
|
13
|
+
*/
|
|
14
14
|
|
|
15
15
|
class DroptargetEntity extends Entity {
|
|
16
16
|
/**
|
|
@@ -18,9 +18,9 @@ class DroptargetEntity extends Entity {
|
|
|
18
18
|
* @name init
|
|
19
19
|
* @memberOf me.DroptargetEntity
|
|
20
20
|
* @function
|
|
21
|
-
* @param {
|
|
22
|
-
* @param {
|
|
23
|
-
* @param {
|
|
21
|
+
* @param {number} x the x postion of the entity
|
|
22
|
+
* @param {number} y the y postion of the entity
|
|
23
|
+
* @param {object} settings the additional entity settings
|
|
24
24
|
*/
|
|
25
25
|
constructor(x, y, settings) {
|
|
26
26
|
super(x, y, settings);
|
|
@@ -28,7 +28,7 @@ class DroptargetEntity extends Entity {
|
|
|
28
28
|
* constant for the overlaps method
|
|
29
29
|
* @public
|
|
30
30
|
* @constant
|
|
31
|
-
* @type
|
|
31
|
+
* @type {string}
|
|
32
32
|
* @name CHECKMETHOD_OVERLAP
|
|
33
33
|
* @memberOf me.DroptargetEntity
|
|
34
34
|
*/
|
|
@@ -37,7 +37,7 @@ class DroptargetEntity extends Entity {
|
|
|
37
37
|
* constant for the contains method
|
|
38
38
|
* @public
|
|
39
39
|
* @constant
|
|
40
|
-
* @type
|
|
40
|
+
* @type {string}
|
|
41
41
|
* @name CHECKMETHOD_CONTAINS
|
|
42
42
|
* @memberOf me.DroptargetEntity
|
|
43
43
|
*/
|
|
@@ -46,7 +46,7 @@ class DroptargetEntity extends Entity {
|
|
|
46
46
|
* the checkmethod we want to use
|
|
47
47
|
* @public
|
|
48
48
|
* @constant
|
|
49
|
-
* @type
|
|
49
|
+
* @type {string}
|
|
50
50
|
* @name checkMethod
|
|
51
51
|
* @memberOf me.DroptargetEntity
|
|
52
52
|
*/
|
|
@@ -60,7 +60,7 @@ class DroptargetEntity extends Entity {
|
|
|
60
60
|
* @name setCheckMethod
|
|
61
61
|
* @memberOf me.DroptargetEntity
|
|
62
62
|
* @function
|
|
63
|
-
* @param {
|
|
63
|
+
* @param {string} checkMethod the checkmethod (defaults to CHECKMETHOD_OVERLAP)
|
|
64
64
|
*/
|
|
65
65
|
setCheckMethod(checkMethod) {
|
|
66
66
|
// We can improve this check,
|
|
@@ -75,7 +75,8 @@ class DroptargetEntity extends Entity {
|
|
|
75
75
|
* @name checkOnMe
|
|
76
76
|
* @memberOf me.DroptargetEntity
|
|
77
77
|
* @function
|
|
78
|
-
* @param {
|
|
78
|
+
* @param {object} e the triggering event
|
|
79
|
+
* @param {object} draggableEntity the draggable entity that is dropped
|
|
79
80
|
*/
|
|
80
81
|
checkOnMe(e, draggableEntity) {
|
|
81
82
|
if (draggableEntity && this.checkMethod(draggableEntity.getBounds())) {
|
|
@@ -89,7 +90,7 @@ class DroptargetEntity extends Entity {
|
|
|
89
90
|
* @name drop
|
|
90
91
|
* @memberOf me.DroptargetEntity
|
|
91
92
|
* @function
|
|
92
|
-
* @param {
|
|
93
|
+
* @param {object} draggableEntity the draggable entity that is dropped
|
|
93
94
|
*/
|
|
94
95
|
drop() {
|
|
95
96
|
|
package/src/entity/entity.js
CHANGED
|
@@ -12,20 +12,20 @@ import Polygon from "./../shapes/poly.js";
|
|
|
12
12
|
* @memberOf me
|
|
13
13
|
* @see me.Renderable
|
|
14
14
|
* @constructor
|
|
15
|
-
* @param {
|
|
16
|
-
* @param {
|
|
17
|
-
* @param {
|
|
15
|
+
* @param {number} x the x coordinates of the entity object
|
|
16
|
+
* @param {number} y the y coordinates of the entity object
|
|
17
|
+
* @param {object} settings Entity properties, to be defined through Tiled or when calling the entity constructor
|
|
18
18
|
* <img src="images/object_properties.png"/>
|
|
19
|
-
* @param {
|
|
20
|
-
* @param {
|
|
21
|
-
* @param {
|
|
22
|
-
* @param {
|
|
23
|
-
* @param {Image|
|
|
19
|
+
* @param {number} settings.width the physical width the entity takes up in game
|
|
20
|
+
* @param {number} settings.height the physical height the entity takes up in game
|
|
21
|
+
* @param {string} [settings.name] object entity name
|
|
22
|
+
* @param {string} [settings.id] object unique IDs
|
|
23
|
+
* @param {Image|string} [settings.image] resource name of a spritesheet to use for the entity renderable component
|
|
24
24
|
* @param {me.Vector2d} [settings.anchorPoint=0.0] Entity anchor point
|
|
25
|
-
* @param {
|
|
26
|
-
* @param {
|
|
27
|
-
* @param {
|
|
28
|
-
* @param {
|
|
25
|
+
* @param {number} [settings.framewidth=settings.width] width of a single frame in the given spritesheet
|
|
26
|
+
* @param {number} [settings.frameheight=settings.width] height of a single frame in the given spritesheet
|
|
27
|
+
* @param {string} [settings.type] object type
|
|
28
|
+
* @param {number} [settings.collisionMask] Mask collision detection for this object
|
|
29
29
|
* @param {me.Rect[]|me.Polygon[]|me.Line[]|me.Ellipse[]} [settings.shapes] the initial list of collision shapes (usually populated through Tiled)
|
|
30
30
|
*/
|
|
31
31
|
|
|
@@ -74,7 +74,7 @@ class Entity extends Renderable {
|
|
|
74
74
|
/**
|
|
75
75
|
* object type (as defined in Tiled)
|
|
76
76
|
* @public
|
|
77
|
-
* @type
|
|
77
|
+
* @type {string}
|
|
78
78
|
* @name type
|
|
79
79
|
* @memberOf me.Entity
|
|
80
80
|
*/
|
|
@@ -83,7 +83,7 @@ class Entity extends Renderable {
|
|
|
83
83
|
/**
|
|
84
84
|
* object unique ID (as defined in Tiled)
|
|
85
85
|
* @public
|
|
86
|
-
* @type
|
|
86
|
+
* @type {number}
|
|
87
87
|
* @name id
|
|
88
88
|
* @memberOf me.Entity
|
|
89
89
|
*/
|
|
@@ -93,7 +93,7 @@ class Entity extends Renderable {
|
|
|
93
93
|
* dead/living state of the entity<br>
|
|
94
94
|
* default value : true
|
|
95
95
|
* @public
|
|
96
|
-
* @type
|
|
96
|
+
* @type {boolean}
|
|
97
97
|
* @name alive
|
|
98
98
|
* @memberOf me.Entity
|
|
99
99
|
*/
|
|
@@ -102,7 +102,7 @@ class Entity extends Renderable {
|
|
|
102
102
|
/**
|
|
103
103
|
* the entity body object
|
|
104
104
|
* @public
|
|
105
|
-
* @type me.Body
|
|
105
|
+
* @type {me.Body}
|
|
106
106
|
* @name body
|
|
107
107
|
* @memberOf me.Entity
|
|
108
108
|
*/
|
|
@@ -134,20 +134,15 @@ class Entity extends Renderable {
|
|
|
134
134
|
/**
|
|
135
135
|
* The entity renderable component (can be any objects deriving from me.Renderable, like me.Sprite for example)
|
|
136
136
|
* @public
|
|
137
|
-
* @type me.Renderable
|
|
137
|
+
* @type {me.Renderable}
|
|
138
138
|
* @name renderable
|
|
139
139
|
* @memberOf me.Entity
|
|
140
140
|
*/
|
|
141
141
|
|
|
142
|
-
/**
|
|
143
|
-
* @ignore
|
|
144
|
-
*/
|
|
145
142
|
get renderable() {
|
|
146
143
|
return this.children[0];
|
|
147
144
|
}
|
|
148
|
-
|
|
149
|
-
* @ignore
|
|
150
|
-
*/
|
|
145
|
+
|
|
151
146
|
set renderable(value) {
|
|
152
147
|
if (value instanceof Renderable) {
|
|
153
148
|
this.children[0] = value;
|
|
@@ -167,10 +162,11 @@ class Entity extends Renderable {
|
|
|
167
162
|
|
|
168
163
|
/**
|
|
169
164
|
* update the bounds position when the body is modified
|
|
170
|
-
* @
|
|
165
|
+
* @ignore
|
|
171
166
|
* @name onBodyUpdate
|
|
172
167
|
* @memberOf me.Entity
|
|
173
168
|
* @function
|
|
169
|
+
* @param {me.Body} the body whose bounds to update
|
|
174
170
|
*/
|
|
175
171
|
onBodyUpdate(body) {
|
|
176
172
|
// update the entity bounds to include the body bounds
|
|
@@ -208,8 +204,8 @@ class Entity extends Renderable {
|
|
|
208
204
|
* @function
|
|
209
205
|
* @protected
|
|
210
206
|
* @param {me.CanvasRenderer|me.WebGLRenderer} renderer a renderer object
|
|
211
|
-
* @param {me.Rect} region to draw
|
|
212
|
-
|
|
207
|
+
* @param {me.Rect} rect region to draw
|
|
208
|
+
*/
|
|
213
209
|
draw(renderer, rect) {
|
|
214
210
|
var renderable = this.renderable;
|
|
215
211
|
if (renderable instanceof Renderable) {
|
package/src/game.js
CHANGED
|
@@ -130,7 +130,7 @@ export function reset () {
|
|
|
130
130
|
* Update the renderer framerate using the system config variables.
|
|
131
131
|
* @function me.game.updateFrameRate
|
|
132
132
|
* @see me.timer.maxfps
|
|
133
|
-
* @see me.
|
|
133
|
+
* @see me.World.fps
|
|
134
134
|
*/
|
|
135
135
|
export function updateFrameRate() {
|
|
136
136
|
// reset the frame counter
|
|
@@ -151,7 +151,7 @@ export function updateFrameRate() {
|
|
|
151
151
|
* Returns the parent container of the specified Child in the game world
|
|
152
152
|
* @function me.game.getParentContainer
|
|
153
153
|
* @param {me.Renderable} child
|
|
154
|
-
* @
|
|
154
|
+
* @returns {me.Container}
|
|
155
155
|
*/
|
|
156
156
|
export function getParentContainer(child) {
|
|
157
157
|
return child.ancestor;
|
|
@@ -170,7 +170,7 @@ export function repaint() {
|
|
|
170
170
|
* update all objects of the game manager
|
|
171
171
|
* @ignore
|
|
172
172
|
* @function me.game.update
|
|
173
|
-
* @param {
|
|
173
|
+
* @param {number} time current timestamp as provided by the RAF callback
|
|
174
174
|
* @param {me.Stage} stage the current stage
|
|
175
175
|
*/
|
|
176
176
|
export function update(time, stage) {
|
package/src/index.js
CHANGED
|
@@ -48,6 +48,7 @@ import BitmapTextData from "./text/bitmaptextdata.js";
|
|
|
48
48
|
import ColorLayer from "./renderable/colorlayer.js";
|
|
49
49
|
import ImageLayer from "./renderable/imagelayer.js";
|
|
50
50
|
import Sprite from "./renderable/sprite.js";
|
|
51
|
+
import NineSliceSprite from "./renderable/nineslicesprite.js";
|
|
51
52
|
import GUI_Object from "./renderable/GUI.js";
|
|
52
53
|
import Collectable from "./renderable/collectable.js";
|
|
53
54
|
import Trigger from "./renderable/trigger.js";
|
|
@@ -78,10 +79,10 @@ import DroptargetEntity from "./entity/droptarget.js";
|
|
|
78
79
|
import * as deprecated from "./lang/deprecated.js";
|
|
79
80
|
|
|
80
81
|
/**
|
|
81
|
-
* (<b>m</b>)elonJS (<b>e</b>)ngine : All melonJS functions are defined inside this namespace.
|
|
82
|
-
* You generally should not add new properties to this namespace as it may be overwritten in future versions.
|
|
83
|
-
* @namespace me
|
|
84
|
-
*/
|
|
82
|
+
* (<b>m</b>)elonJS (<b>e</b>)ngine : All melonJS functions are defined inside this namespace.
|
|
83
|
+
* You generally should not add new properties to this namespace as it may be overwritten in future versions.
|
|
84
|
+
* @namespace me
|
|
85
|
+
*/
|
|
85
86
|
|
|
86
87
|
/**
|
|
87
88
|
* current melonJS version
|
|
@@ -145,6 +146,7 @@ export {
|
|
|
145
146
|
ColorLayer,
|
|
146
147
|
ImageLayer,
|
|
147
148
|
Sprite,
|
|
149
|
+
NineSliceSprite,
|
|
148
150
|
GUI_Object,
|
|
149
151
|
Collectable,
|
|
150
152
|
Trigger,
|
|
@@ -179,17 +181,17 @@ export {
|
|
|
179
181
|
|
|
180
182
|
|
|
181
183
|
/**
|
|
182
|
-
* a flag indicating that melonJS is fully initialized
|
|
183
|
-
* @type {
|
|
184
|
-
* @default false
|
|
185
|
-
* @readonly
|
|
186
|
-
* @memberOf me
|
|
187
|
-
*/
|
|
184
|
+
* a flag indicating that melonJS is fully initialized
|
|
185
|
+
* @type {boolean}
|
|
186
|
+
* @default false
|
|
187
|
+
* @readonly
|
|
188
|
+
* @memberOf me
|
|
189
|
+
*/
|
|
188
190
|
export var initialized = false;
|
|
189
191
|
|
|
190
192
|
/**
|
|
191
193
|
* disable melonJS auto-initialization
|
|
192
|
-
* @type {
|
|
194
|
+
* @type {boolean}
|
|
193
195
|
* @default false
|
|
194
196
|
* @see me.boot
|
|
195
197
|
* @memberOf me
|
|
@@ -220,6 +222,7 @@ export function boot() {
|
|
|
220
222
|
pool.register("me.Color", Color, true);
|
|
221
223
|
pool.register("me.Particle", Particle, true);
|
|
222
224
|
pool.register("me.Sprite", Sprite);
|
|
225
|
+
pool.register("me.NineSliceSprite", NineSliceSprite);
|
|
223
226
|
pool.register("me.Renderable", Renderable);
|
|
224
227
|
pool.register("me.Text", Text, true);
|
|
225
228
|
pool.register("me.BitmapText", BitmapText);
|
|
@@ -246,6 +249,7 @@ export function boot() {
|
|
|
246
249
|
pool.register("Color", Color, true);
|
|
247
250
|
pool.register("Particle", Particle, true);
|
|
248
251
|
pool.register("Sprite", Sprite);
|
|
252
|
+
pool.register("NineSliceSprite", NineSliceSprite);
|
|
249
253
|
pool.register("Renderable", Renderable);
|
|
250
254
|
pool.register("Text", Text, true);
|
|
251
255
|
pool.register("BitmapText", BitmapText);
|
package/src/input/gamepad.js
CHANGED
|
@@ -296,7 +296,7 @@ export var GAMEPAD = {
|
|
|
296
296
|
* </ul>
|
|
297
297
|
* @public
|
|
298
298
|
* @name AXES
|
|
299
|
-
* @enum {
|
|
299
|
+
* @enum {number}
|
|
300
300
|
* @memberOf me.input.GAMEPAD
|
|
301
301
|
* @see https://w3c.github.io/gamepad/#remapping
|
|
302
302
|
*/
|
|
@@ -323,7 +323,7 @@ export var GAMEPAD = {
|
|
|
323
323
|
* </ul>
|
|
324
324
|
* @public
|
|
325
325
|
* @name BUTTONS
|
|
326
|
-
* @enum {
|
|
326
|
+
* @enum {number}
|
|
327
327
|
* @memberOf me.input.GAMEPAD
|
|
328
328
|
* @see https://w3c.github.io/gamepad/#remapping
|
|
329
329
|
*/
|
|
@@ -360,11 +360,11 @@ export var GAMEPAD = {
|
|
|
360
360
|
* @memberOf me.input
|
|
361
361
|
* @public
|
|
362
362
|
* @function
|
|
363
|
-
* @param {
|
|
364
|
-
* @param {
|
|
365
|
-
* @param {
|
|
363
|
+
* @param {number} index Gamepad index
|
|
364
|
+
* @param {object} button Button/Axis definition
|
|
365
|
+
* @param {string} button.type "buttons" or "axes"
|
|
366
366
|
* @param {me.input.GAMEPAD.BUTTONS|me.input.GAMEPAD.AXES} button.code button or axis code id
|
|
367
|
-
* @param {
|
|
367
|
+
* @param {number} [button.threshold=1] value indicating when the axis should trigger the keycode (e.g. -0.5 or 0.5)
|
|
368
368
|
* @param {me.input.KEY} keyCode
|
|
369
369
|
* @example
|
|
370
370
|
* // enable the keyboard
|
|
@@ -435,7 +435,7 @@ export function bindGamepad(index, button, keyCode) {
|
|
|
435
435
|
* @memberOf me.input
|
|
436
436
|
* @public
|
|
437
437
|
* @function
|
|
438
|
-
* @param {
|
|
438
|
+
* @param {number} index Gamepad index
|
|
439
439
|
* @param {me.input.GAMEPAD.BUTTONS} button
|
|
440
440
|
* @example
|
|
441
441
|
* me.input.unbindGamepad(0, me.input.GAMEPAD.BUTTONS.FACE_1);
|
|
@@ -454,7 +454,7 @@ export function unbindGamepad(index, button) {
|
|
|
454
454
|
* @memberOf me.input
|
|
455
455
|
* @public
|
|
456
456
|
* @function
|
|
457
|
-
* @param {
|
|
457
|
+
* @param {number} value Deadzone value
|
|
458
458
|
*/
|
|
459
459
|
export function setGamepadDeadzone(value) {
|
|
460
460
|
deadzone = value;
|
|
@@ -468,11 +468,11 @@ export function setGamepadDeadzone(value) {
|
|
|
468
468
|
* @memberOf me.input
|
|
469
469
|
* @public
|
|
470
470
|
* @function
|
|
471
|
-
* @param {
|
|
472
|
-
* @param {
|
|
473
|
-
* @param {
|
|
474
|
-
* @param {
|
|
475
|
-
* @param {
|
|
471
|
+
* @param {string} id Gamepad id string
|
|
472
|
+
* @param {object} mapping A hash table
|
|
473
|
+
* @param {number[]} mapping.axes Standard analog control stick axis locations
|
|
474
|
+
* @param {number[]} mapping.buttons Standard digital button locations
|
|
475
|
+
* @param {number[]} [mapping.analog] Analog axis locations for buttons
|
|
476
476
|
* @param {Function} [mapping.normalize_fn] a function that returns a normalized value in range [-1.0..1.0] for the given value, axis and button
|
|
477
477
|
* @example
|
|
478
478
|
* // A weird controller that has its axis mappings reversed
|
package/src/input/input.js
CHANGED
package/src/input/keyboard.js
CHANGED
|
@@ -98,7 +98,7 @@ var keyUpEvent = function (e, keyCode, mouseButton) {
|
|
|
98
98
|
/**
|
|
99
99
|
* the default target element for keyboard events (usually the window element in which the game is running)
|
|
100
100
|
* @public
|
|
101
|
-
* @type EventTarget
|
|
101
|
+
* @type {EventTarget}
|
|
102
102
|
* @name keyBoardEventTarget
|
|
103
103
|
* @memberOf me.input
|
|
104
104
|
*/
|
|
@@ -331,18 +331,15 @@ export function initKeyboardEvent() {
|
|
|
331
331
|
* @memberOf me.input
|
|
332
332
|
* @public
|
|
333
333
|
* @function
|
|
334
|
-
* @param {
|
|
335
|
-
* @
|
|
334
|
+
* @param {string} action user defined corresponding action
|
|
335
|
+
* @returns {boolean} true if pressed
|
|
336
336
|
* @example
|
|
337
|
-
* if (me.input.isKeyPressed('left'))
|
|
338
|
-
* {
|
|
337
|
+
* if (me.input.isKeyPressed('left')) {
|
|
339
338
|
* //do something
|
|
340
339
|
* }
|
|
341
|
-
* else if (me.input.isKeyPressed('right'))
|
|
342
|
-
* {
|
|
340
|
+
* else if (me.input.isKeyPressed('right')) {
|
|
343
341
|
* //do something else...
|
|
344
342
|
* }
|
|
345
|
-
*
|
|
346
343
|
*/
|
|
347
344
|
export function isKeyPressed(action) {
|
|
348
345
|
if (_keyStatus[action] && !_keyLocked[action]) {
|
|
@@ -360,8 +357,8 @@ export function isKeyPressed(action) {
|
|
|
360
357
|
* @memberOf me.input
|
|
361
358
|
* @public
|
|
362
359
|
* @function
|
|
363
|
-
* @param {
|
|
364
|
-
* @
|
|
360
|
+
* @param {string} action user defined corresponding action
|
|
361
|
+
* @returns {boolean} down (true) or up(false)
|
|
365
362
|
*/
|
|
366
363
|
export function keyStatus(action) {
|
|
367
364
|
return (_keyStatus[action] > 0);
|
|
@@ -375,7 +372,8 @@ export function keyStatus(action) {
|
|
|
375
372
|
* @public
|
|
376
373
|
* @function
|
|
377
374
|
* @param {me.input.KEY} keycode
|
|
378
|
-
* @param {
|
|
375
|
+
* @param {boolean} [status=false] true to trigger a key down event, or false for key up event
|
|
376
|
+
* @param {number} [mouseButton] the mouse button to trigger
|
|
379
377
|
* @example
|
|
380
378
|
* // trigger a key press
|
|
381
379
|
* me.input.triggerKeyEvent(me.input.KEY.LEFT, true);
|
|
@@ -397,9 +395,9 @@ export function triggerKeyEvent(keycode, status, mouseButton) {
|
|
|
397
395
|
* @public
|
|
398
396
|
* @function
|
|
399
397
|
* @param {me.input.KEY} keycode
|
|
400
|
-
* @param {
|
|
401
|
-
* @param {
|
|
402
|
-
* @param {
|
|
398
|
+
* @param {string} action user defined corresponding action
|
|
399
|
+
* @param {boolean} [lock=false] cancel the keypress event once read
|
|
400
|
+
* @param {boolean} [preventDefault=me.input.preventDefault] prevent default browser action
|
|
403
401
|
* @example
|
|
404
402
|
* // enable the keyboard
|
|
405
403
|
* me.input.bindKey(me.input.KEY.LEFT, "left");
|
|
@@ -424,7 +422,7 @@ export function bindKey(keycode, action, lock, preventDefault = preventDefaultAc
|
|
|
424
422
|
* @public
|
|
425
423
|
* @function
|
|
426
424
|
* @param {me.input.KEY} keycode
|
|
427
|
-
* @
|
|
425
|
+
* @returns {string} user defined associated action
|
|
428
426
|
*/
|
|
429
427
|
export function getBindingKey(keycode) {
|
|
430
428
|
return _keyBindings[keycode];
|
|
@@ -436,7 +434,7 @@ export function getBindingKey(keycode) {
|
|
|
436
434
|
* @memberOf me.input
|
|
437
435
|
* @public
|
|
438
436
|
* @function
|
|
439
|
-
* @param {
|
|
437
|
+
* @param {string} action user defined corresponding action
|
|
440
438
|
* @example
|
|
441
439
|
* // Unlock jump when touching the ground
|
|
442
440
|
* if (!this.falling && !this.jumping) {
|