melonjs 13.4.0 → 14.0.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 +4 -6
- package/dist/melonjs.module.d.ts +13108 -11652
- package/dist/melonjs.module.js +642 -187
- package/package.json +21 -21
- package/src/application/application.js +3 -3
- package/src/audio/audio.js +27 -27
- package/src/camera/camera2d.js +1 -2
- package/src/entity/entity.js +1 -2
- package/src/geometries/ellipse.js +1 -2
- package/src/geometries/line.js +2 -3
- package/src/geometries/poly.js +2 -2
- package/src/geometries/rectangle.js +1 -3
- package/src/geometries/roundrect.js +1 -2
- package/src/index.js +8 -4
- package/src/input/gamepad.js +12 -12
- package/src/input/keyboard.js +8 -8
- package/src/input/pointer.js +1 -1
- package/src/input/pointerevent.js +9 -9
- package/src/lang/deprecated.js +21 -2
- package/src/level/level.js +2 -2
- package/src/level/tiled/TMXGroup.js +1 -1
- package/src/level/tiled/TMXLayer.js +1 -1
- package/src/level/tiled/TMXTile.js +2 -2
- package/src/level/tiled/TMXTileMap.js +4 -4
- package/src/level/tiled/TMXTileset.js +2 -2
- package/src/level/tiled/TMXTilesetGroup.js +1 -1
- package/src/level/tiled/TMXUtils.js +7 -7
- package/src/level/tiled/renderer/TMXHexagonalRenderer.js +1 -1
- package/src/level/tiled/renderer/TMXIsometricRenderer.js +1 -1
- package/src/level/tiled/renderer/TMXOrthogonalRenderer.js +1 -1
- package/src/level/tiled/renderer/TMXRenderer.js +1 -1
- package/src/level/tiled/renderer/TMXStaggeredRenderer.js +1 -1
- package/src/loader/loader.js +9 -9
- package/src/loader/loadingscreen.js +2 -2
- package/src/math/color.js +3 -3
- package/src/math/math.js +10 -10
- package/src/math/matrix2.js +1 -1
- package/src/math/matrix3.js +1 -1
- package/src/math/observable_vector2.js +1 -1
- package/src/math/observable_vector3.js +1 -1
- package/src/math/vector2.js +1 -1
- package/src/math/vector3.js +1 -1
- package/src/particles/emitter.js +2 -2
- package/src/particles/particle.js +1 -1
- package/src/physics/body.js +2 -2
- package/src/physics/bounds.js +10 -7
- package/src/physics/detector.js +56 -55
- package/src/physics/quadtree.js +3 -3
- package/src/physics/world.js +2 -2
- package/src/polyfill/performance.js +1 -1
- package/src/polyfill/requestAnimationFrame.js +1 -1
- package/src/renderable/collectable.js +1 -1
- package/src/renderable/colorlayer.js +1 -1
- package/src/renderable/container.js +10 -6
- package/src/renderable/dragndrop.js +2 -2
- package/src/renderable/imagelayer.js +1 -2
- package/src/renderable/light2d.js +1 -1
- package/src/renderable/nineslicesprite.js +1 -2
- package/src/renderable/renderable.js +1 -3
- package/src/renderable/sprite.js +3 -4
- package/src/renderable/trigger.js +3 -4
- package/src/renderable/ui/uibaseelement.js +204 -0
- package/src/renderable/{GUI.js → ui/uispriteelement.js} +8 -35
- package/src/renderable/ui/uitextbutton.js +121 -0
- package/src/state/stage.js +4 -5
- package/src/system/device.js +27 -27
- package/src/system/dom.js +1 -1
- package/src/system/event.js +4 -4
- package/src/system/pooling.js +2 -3
- package/src/system/save.js +2 -2
- package/src/system/timer.js +1 -1
- package/src/text/bitmaptext.js +2 -3
- package/src/text/bitmaptextdata.js +4 -7
- package/src/text/glyph.js +1 -2
- package/src/text/text.js +2 -3
- package/src/text/textstyle.js +1 -1
- package/src/tweens/tween.js +2 -3
- package/src/utils/agent.js +4 -4
- package/src/utils/array.js +3 -3
- package/src/utils/file.js +2 -2
- package/src/utils/function.js +3 -3
- package/src/utils/string.js +5 -5
- package/src/utils/utils.js +2 -2
- package/src/video/canvas/canvas_renderer.js +1 -2
- package/src/video/renderer.js +2 -3
- package/src/video/texture/atlas.js +2 -2
- package/src/video/texture/cache.js +1 -2
- package/src/video/video.js +12 -14
- package/src/video/webgl/buffer/vertex.js +1 -2
- package/src/video/webgl/glshader.js +1 -2
- package/src/video/webgl/utils/attributes.js +1 -1
- package/src/video/webgl/utils/precision.js +1 -1
- package/src/video/webgl/utils/program.js +2 -2
- package/src/video/webgl/utils/string.js +1 -1
- package/src/video/webgl/utils/uniforms.js +3 -3
- package/src/video/webgl/webgl_compositor.js +1 -2
- package/src/video/webgl/webgl_renderer.js +1 -2
- package/dist/melonjs.js +0 -37922
- package/dist/melonjs.min.js +0 -29
package/src/physics/detector.js
CHANGED
|
@@ -2,6 +2,8 @@ import * as SAT from "./sat.js";
|
|
|
2
2
|
import ResponseObject from "./response.js";
|
|
3
3
|
import Vector2d from "./../math/vector2.js";
|
|
4
4
|
import game from "./../game.js";
|
|
5
|
+
import Bounds from "./bounds.js";
|
|
6
|
+
|
|
5
7
|
|
|
6
8
|
// a dummy object when using Line for raycasting
|
|
7
9
|
let dummyObj = {
|
|
@@ -14,6 +16,9 @@ let dummyObj = {
|
|
|
14
16
|
}
|
|
15
17
|
};
|
|
16
18
|
|
|
19
|
+
let boundsA = new Bounds();
|
|
20
|
+
let boundsB = new Bounds();
|
|
21
|
+
|
|
17
22
|
// the global response object used for collisions
|
|
18
23
|
let globalResponse = new ResponseObject();
|
|
19
24
|
|
|
@@ -28,14 +33,18 @@ let globalResponse = new ResponseObject();
|
|
|
28
33
|
* @returns {boolean} true if they should collide, false otherwise
|
|
29
34
|
*/
|
|
30
35
|
function shouldCollide(a, b) {
|
|
36
|
+
var bodyA = a.body,
|
|
37
|
+
bodyB = b.body;
|
|
31
38
|
return (
|
|
39
|
+
a !== b &&
|
|
32
40
|
a.isKinematic !== true && b.isKinematic !== true &&
|
|
33
|
-
typeof
|
|
34
|
-
|
|
35
|
-
(
|
|
36
|
-
(
|
|
41
|
+
typeof bodyA === "object" && typeof bodyB === "object" &&
|
|
42
|
+
bodyA.shapes.length > 0 && bodyB.shapes.length > 0 &&
|
|
43
|
+
!(bodyA.isStatic === true && bodyB.isStatic === true) &&
|
|
44
|
+
(bodyA.collisionMask & bodyB.collisionType) !== 0 &&
|
|
45
|
+
(bodyA.collisionType & bodyB.collisionMask) !== 0
|
|
37
46
|
);
|
|
38
|
-
}
|
|
47
|
+
}
|
|
39
48
|
|
|
40
49
|
|
|
41
50
|
|
|
@@ -52,63 +61,55 @@ export function collisionCheck(objA, response = globalResponse) {
|
|
|
52
61
|
// retreive a list of potential colliding objects from the game world
|
|
53
62
|
var candidates = game.world.broadphase.retrieve(objA);
|
|
54
63
|
|
|
55
|
-
|
|
64
|
+
boundsA.addBounds(objA.getBounds(), true);
|
|
65
|
+
boundsA.addBounds(objA.body.getBounds());
|
|
56
66
|
|
|
67
|
+
candidates.forEach((objB) => {
|
|
57
68
|
// check if both objects "should" collide
|
|
58
|
-
if (
|
|
59
|
-
// fast AABB check if both bounding boxes are overlaping
|
|
60
|
-
objA.body.getBounds().overlaps(objB.body.getBounds())) {
|
|
69
|
+
if (shouldCollide(objA, objB)) {
|
|
61
70
|
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
var bLen = objB.body.shapes.length;
|
|
65
|
-
if (aLen === 0 || bLen === 0) {
|
|
66
|
-
continue;
|
|
67
|
-
}
|
|
71
|
+
boundsB.addBounds(objB.getBounds(), true);
|
|
72
|
+
boundsB.addBounds(objB.body.getBounds());
|
|
68
73
|
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
if (objB.onCollision && objB.onCollision(response, objA) !== false && objB.body.isStatic === false) {
|
|
100
|
-
objB.body.respondToCollision.call(objB.body, response);
|
|
74
|
+
// fast AABB check if both bounding boxes are overlaping
|
|
75
|
+
if (boundsA.overlaps(boundsB)) {
|
|
76
|
+
// for each shape in body A
|
|
77
|
+
objA.body.shapes.forEach((shapeA, indexA) => {
|
|
78
|
+
// for each shape in body B
|
|
79
|
+
objB.body.shapes.forEach((shapeB, indexB) => {
|
|
80
|
+
// full SAT collision check
|
|
81
|
+
if (SAT["test" + shapeA.shapeType + shapeB.shapeType].call(
|
|
82
|
+
this,
|
|
83
|
+
objA, // a reference to the object A
|
|
84
|
+
shapeA,
|
|
85
|
+
objB, // a reference to the object B
|
|
86
|
+
shapeB,
|
|
87
|
+
// clear response object before reusing
|
|
88
|
+
response.clear()) === true
|
|
89
|
+
) {
|
|
90
|
+
// we touched something !
|
|
91
|
+
collisionCounter++;
|
|
92
|
+
|
|
93
|
+
// set the shape index
|
|
94
|
+
response.indexShapeA = indexA;
|
|
95
|
+
response.indexShapeB = indexB;
|
|
96
|
+
|
|
97
|
+
// execute the onCollision callback
|
|
98
|
+
if (objA.onCollision && objA.onCollision(response, objB) !== false && objA.body.isStatic === false) {
|
|
99
|
+
objA.body.respondToCollision.call(objA.body, response);
|
|
100
|
+
}
|
|
101
|
+
if (objB.onCollision && objB.onCollision(response, objA) !== false && objB.body.isStatic === false) {
|
|
102
|
+
objB.body.respondToCollision.call(objB.body, response);
|
|
103
|
+
}
|
|
101
104
|
}
|
|
102
|
-
}
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
indexA++;
|
|
106
|
-
} while (indexA < aLen);
|
|
105
|
+
});
|
|
106
|
+
});
|
|
107
|
+
}
|
|
107
108
|
}
|
|
108
|
-
}
|
|
109
|
+
});
|
|
109
110
|
// we could return the amount of objects we collided with ?
|
|
110
111
|
return collisionCounter > 0;
|
|
111
|
-
}
|
|
112
|
+
}
|
|
112
113
|
|
|
113
114
|
/**
|
|
114
115
|
* Checks for object colliding with the given line
|
|
@@ -182,4 +183,4 @@ export function rayCast(line, result = []) {
|
|
|
182
183
|
|
|
183
184
|
// return the list of colliding objects
|
|
184
185
|
return result;
|
|
185
|
-
}
|
|
186
|
+
}
|
package/src/physics/quadtree.js
CHANGED
|
@@ -32,7 +32,7 @@ function QT_ARRAY_POP(world, bounds, max_objects = 4, max_levels = 4, level = 0)
|
|
|
32
32
|
} else {
|
|
33
33
|
return new QuadTree(world, bounds, max_objects, max_levels, level);
|
|
34
34
|
}
|
|
35
|
-
}
|
|
35
|
+
}
|
|
36
36
|
|
|
37
37
|
/**
|
|
38
38
|
* Push back a quadtree back into the array
|
|
@@ -40,7 +40,7 @@ function QT_ARRAY_POP(world, bounds, max_objects = 4, max_levels = 4, level = 0)
|
|
|
40
40
|
*/
|
|
41
41
|
function QT_ARRAY_PUSH(qt) {
|
|
42
42
|
QT_ARRAY.push(qt);
|
|
43
|
-
}
|
|
43
|
+
}
|
|
44
44
|
|
|
45
45
|
/**
|
|
46
46
|
* a temporary vector object to be reused
|
|
@@ -156,7 +156,7 @@ class QuadTree {
|
|
|
156
156
|
if (item.isFloating === true) {
|
|
157
157
|
pos = this.world.app.viewport.localToWorld(bounds.left, bounds.top, QT_VECTOR);
|
|
158
158
|
} else {
|
|
159
|
-
pos = QT_VECTOR.set(
|
|
159
|
+
pos = QT_VECTOR.set(bounds.left, bounds.top);
|
|
160
160
|
}
|
|
161
161
|
|
|
162
162
|
var index = -1,
|
package/src/physics/world.js
CHANGED
|
@@ -194,7 +194,7 @@ class World extends Container {
|
|
|
194
194
|
if (body.update(dt) === true) {
|
|
195
195
|
// mark ancestor as dirty
|
|
196
196
|
ancestor.isDirty = true;
|
|
197
|
-
}
|
|
197
|
+
}
|
|
198
198
|
// handle collisions against other objects
|
|
199
199
|
collisionCheck(ancestor);
|
|
200
200
|
// clear body force
|
|
@@ -207,6 +207,6 @@ class World extends Container {
|
|
|
207
207
|
return super.update(dt);
|
|
208
208
|
}
|
|
209
209
|
|
|
210
|
-
}
|
|
210
|
+
}
|
|
211
211
|
|
|
212
212
|
export default World;
|
|
@@ -8,7 +8,7 @@ Date.now = (Date.now || function () { // thanks IE8
|
|
|
8
8
|
|
|
9
9
|
if ("now" in globalThis.performance === false) {
|
|
10
10
|
|
|
11
|
-
|
|
11
|
+
let nowOffset = Date.now();
|
|
12
12
|
|
|
13
13
|
if (performance.timing && performance.timing.navigationStart) {
|
|
14
14
|
nowOffset = performance.timing.navigationStart;
|
|
@@ -22,7 +22,7 @@ if (!requestAnimationFrame || !cancelAnimationFrame) {
|
|
|
22
22
|
requestAnimationFrame = function (callback) {
|
|
23
23
|
var currTime = globalThis.performance.now();
|
|
24
24
|
var timeToCall = Math.max(0, (1000 / timer.maxfps) - (currTime - lastTime));
|
|
25
|
-
var id = globalThis.setTimeout(
|
|
25
|
+
var id = globalThis.setTimeout(() => {
|
|
26
26
|
callback(currTime + timeToCall);
|
|
27
27
|
}, timeToCall);
|
|
28
28
|
lastTime = currTime + timeToCall;
|
|
@@ -28,10 +28,14 @@ class Container extends Renderable {
|
|
|
28
28
|
* @param {number} [width=game.viewport.width] width of the container
|
|
29
29
|
* @param {number} [height=game.viewport.height] height of the container
|
|
30
30
|
*/
|
|
31
|
-
constructor(x = 0, y = 0, width
|
|
31
|
+
constructor(x = 0, y = 0, width, height, root = false) {
|
|
32
32
|
|
|
33
33
|
// call the super constructor
|
|
34
|
-
super(
|
|
34
|
+
super(
|
|
35
|
+
x, y,
|
|
36
|
+
typeof width === "undefined" ? (typeof game.viewport !== "undefined" ? game.viewport.width : Infinity) : width,
|
|
37
|
+
typeof height === "undefined" ? (typeof game.viewport !== "undefined" ? game.viewport.height : Infinity) : height
|
|
38
|
+
);
|
|
35
39
|
|
|
36
40
|
/**
|
|
37
41
|
* keep track of pending sort
|
|
@@ -171,7 +175,7 @@ class Container extends Renderable {
|
|
|
171
175
|
if (child && child.isPersistent !== true) {
|
|
172
176
|
this.removeChildNow(child);
|
|
173
177
|
}
|
|
174
|
-
}
|
|
178
|
+
}
|
|
175
179
|
|
|
176
180
|
if (typeof this.currentTransform !== "undefined") {
|
|
177
181
|
// just reset some variables
|
|
@@ -912,10 +916,10 @@ class Container extends Renderable {
|
|
|
912
916
|
// check if object is in any active cameras
|
|
913
917
|
obj.inViewport = false;
|
|
914
918
|
// iterate through all cameras
|
|
915
|
-
state.current().cameras.forEach(
|
|
919
|
+
state.current().cameras.forEach((camera) => {
|
|
916
920
|
if (camera.isVisible(obj, isFloating)) {
|
|
917
921
|
obj.inViewport = true;
|
|
918
|
-
}
|
|
922
|
+
}
|
|
919
923
|
});
|
|
920
924
|
|
|
921
925
|
// update our object
|
|
@@ -1000,6 +1004,6 @@ class Container extends Renderable {
|
|
|
1000
1004
|
}
|
|
1001
1005
|
}
|
|
1002
1006
|
}
|
|
1003
|
-
}
|
|
1007
|
+
}
|
|
1004
1008
|
|
|
1005
1009
|
export default Container;
|
|
@@ -109,7 +109,7 @@ export class Draggable extends Renderable {
|
|
|
109
109
|
input.releasePointerEvent("pointercancel", this);
|
|
110
110
|
super.destroy();
|
|
111
111
|
}
|
|
112
|
-
}
|
|
112
|
+
}
|
|
113
113
|
|
|
114
114
|
/**
|
|
115
115
|
* @classdesc
|
|
@@ -212,4 +212,4 @@ export class DropTarget extends Renderable {
|
|
|
212
212
|
event.off(event.DRAGEND, this.checkOnMe);
|
|
213
213
|
super.destroy();
|
|
214
214
|
}
|
|
215
|
-
}
|
|
215
|
+
}
|
package/src/renderable/sprite.js
CHANGED
|
@@ -200,7 +200,7 @@ class Sprite extends Renderable {
|
|
|
200
200
|
// displaying order
|
|
201
201
|
if (typeof settings.z !== "undefined") {
|
|
202
202
|
this.pos.z = settings.z;
|
|
203
|
-
}
|
|
203
|
+
}
|
|
204
204
|
|
|
205
205
|
// for sprite, addAnimation will return !=0
|
|
206
206
|
if (this.addAnimation("default", null) !== 0) {
|
|
@@ -301,7 +301,7 @@ class Sprite extends Renderable {
|
|
|
301
301
|
if (index == null) {
|
|
302
302
|
index = [];
|
|
303
303
|
// create a default animation with all frame
|
|
304
|
-
Object.keys(this.textureAtlas).forEach(
|
|
304
|
+
Object.keys(this.textureAtlas).forEach((v, i) => {
|
|
305
305
|
index[i] = i;
|
|
306
306
|
});
|
|
307
307
|
}
|
|
@@ -641,6 +641,5 @@ class Sprite extends Renderable {
|
|
|
641
641
|
w, h // dw,dh
|
|
642
642
|
);
|
|
643
643
|
}
|
|
644
|
-
}
|
|
645
|
-
|
|
644
|
+
}
|
|
646
645
|
export default Sprite;
|
|
@@ -60,11 +60,11 @@ class Trigger extends Renderable {
|
|
|
60
60
|
event: "level"
|
|
61
61
|
};
|
|
62
62
|
|
|
63
|
-
[ "type", "container", "onLoaded", "flatten", "setViewportBounds", "to" ].forEach(
|
|
63
|
+
[ "type", "container", "onLoaded", "flatten", "setViewportBounds", "to" ].forEach((property) => {
|
|
64
64
|
if (typeof settings[property] !== "undefined") {
|
|
65
65
|
this.triggerSettings[property] = settings[property];
|
|
66
66
|
}
|
|
67
|
-
}
|
|
67
|
+
});
|
|
68
68
|
|
|
69
69
|
// add and configure the physic body
|
|
70
70
|
var shape = settings.shapes;
|
|
@@ -144,6 +144,5 @@ class Trigger extends Renderable {
|
|
|
144
144
|
return false;
|
|
145
145
|
}
|
|
146
146
|
|
|
147
|
-
}
|
|
148
|
-
|
|
147
|
+
}
|
|
149
148
|
export default Trigger;
|
|
@@ -0,0 +1,204 @@
|
|
|
1
|
+
import Container from "./../container.js";
|
|
2
|
+
import timer from "../../system/timer.js";
|
|
3
|
+
import { registerPointerEvent, releasePointerEvent} from "./../../input/input.js";
|
|
4
|
+
|
|
5
|
+
/**
|
|
6
|
+
* @classdesc
|
|
7
|
+
* This is a basic clickable container which you can use in your game UI.
|
|
8
|
+
* Use this for example if you want to display a button which contains
|
|
9
|
+
* text and images.
|
|
10
|
+
* @augments Container
|
|
11
|
+
*/
|
|
12
|
+
class UIBaseElement extends Container {
|
|
13
|
+
/**
|
|
14
|
+
*
|
|
15
|
+
* @param {number} x The x position of the container
|
|
16
|
+
* @param {number} y The y position of the container
|
|
17
|
+
* @param {number} w width of the container (default: viewport width)
|
|
18
|
+
* @param {number} h height of the container (default: viewport height)
|
|
19
|
+
*/
|
|
20
|
+
constructor(x, y, w, h) {
|
|
21
|
+
super(x, y, w, h);
|
|
22
|
+
/**
|
|
23
|
+
* object can be clicked or not
|
|
24
|
+
* @type {boolean}
|
|
25
|
+
*/
|
|
26
|
+
this.isClickable = true;
|
|
27
|
+
|
|
28
|
+
/**
|
|
29
|
+
* Tap and hold threshold timeout in ms
|
|
30
|
+
* @type {number}
|
|
31
|
+
* @default 250
|
|
32
|
+
*/
|
|
33
|
+
this.holdThreshold = 250;
|
|
34
|
+
|
|
35
|
+
/**
|
|
36
|
+
* object can be tap and hold
|
|
37
|
+
* @type {boolean}
|
|
38
|
+
* @default false
|
|
39
|
+
*/
|
|
40
|
+
this.isHoldable = false;
|
|
41
|
+
|
|
42
|
+
/**
|
|
43
|
+
* true if the pointer is over the object
|
|
44
|
+
* @type {boolean}
|
|
45
|
+
* @default false
|
|
46
|
+
*/
|
|
47
|
+
this.hover = false;
|
|
48
|
+
|
|
49
|
+
// object has been updated (clicked,etc..)
|
|
50
|
+
this.holdTimeout = null;
|
|
51
|
+
this.released = true;
|
|
52
|
+
|
|
53
|
+
// GUI items use screen coordinates
|
|
54
|
+
this.floating = true;
|
|
55
|
+
|
|
56
|
+
// enable event detection
|
|
57
|
+
this.isKinematic = false;
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
/**
|
|
61
|
+
* function callback for the pointerdown event
|
|
62
|
+
* @ignore
|
|
63
|
+
*/
|
|
64
|
+
clicked(event) {
|
|
65
|
+
// Check if left mouse button is pressed
|
|
66
|
+
if (event.button === 0 && this.isClickable) {
|
|
67
|
+
this.dirty = true;
|
|
68
|
+
this.released = false;
|
|
69
|
+
if (this.isHoldable) {
|
|
70
|
+
if (this.holdTimeout !== null) {
|
|
71
|
+
timer.clearTimeout(this.holdTimeout);
|
|
72
|
+
}
|
|
73
|
+
this.holdTimeout = timer.setTimeout(
|
|
74
|
+
this.hold.bind(this),
|
|
75
|
+
this.holdThreshold,
|
|
76
|
+
false
|
|
77
|
+
);
|
|
78
|
+
this.released = false;
|
|
79
|
+
}
|
|
80
|
+
return this.onClick(event);
|
|
81
|
+
}
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
/**
|
|
85
|
+
* function called when the object is pressed (to be extended)
|
|
86
|
+
* @param {Pointer} event the event object
|
|
87
|
+
* @returns {boolean} return false if we need to stop propagating the event
|
|
88
|
+
*/
|
|
89
|
+
onClick(event) { // eslint-disable-line no-unused-vars
|
|
90
|
+
return false;
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
/**
|
|
94
|
+
* function callback for the pointerEnter event
|
|
95
|
+
* @ignore
|
|
96
|
+
*/
|
|
97
|
+
enter(event) {
|
|
98
|
+
this.hover = true;
|
|
99
|
+
this.dirty = true;
|
|
100
|
+
return this.onOver(event);
|
|
101
|
+
}
|
|
102
|
+
|
|
103
|
+
/**
|
|
104
|
+
* function called when the pointer is over the object
|
|
105
|
+
* @param {Pointer} event the event object
|
|
106
|
+
*/
|
|
107
|
+
onOver(event) { // eslint-disable-line no-unused-vars
|
|
108
|
+
// to be extended
|
|
109
|
+
}
|
|
110
|
+
|
|
111
|
+
/**
|
|
112
|
+
* function callback for the pointerLeave event
|
|
113
|
+
* @ignore
|
|
114
|
+
*/
|
|
115
|
+
leave(event) {
|
|
116
|
+
this.hover = false;
|
|
117
|
+
this.dirty = true;
|
|
118
|
+
this.release(event);
|
|
119
|
+
return this.onOut(event);
|
|
120
|
+
}
|
|
121
|
+
|
|
122
|
+
/**
|
|
123
|
+
* function called when the pointer is leaving the object area
|
|
124
|
+
* @param {Pointer} event the event object
|
|
125
|
+
*/
|
|
126
|
+
onOut(event) { // eslint-disable-line no-unused-vars
|
|
127
|
+
// to be extended
|
|
128
|
+
}
|
|
129
|
+
|
|
130
|
+
/**
|
|
131
|
+
* function callback for the pointerup event
|
|
132
|
+
* @ignore
|
|
133
|
+
*/
|
|
134
|
+
release(event) {
|
|
135
|
+
if (this.released === false) {
|
|
136
|
+
this.released = true;
|
|
137
|
+
this.dirty = true;
|
|
138
|
+
timer.clearTimeout(this.holdTimeout);
|
|
139
|
+
return this.onRelease(event);
|
|
140
|
+
}
|
|
141
|
+
}
|
|
142
|
+
|
|
143
|
+
/**
|
|
144
|
+
* function called when the object is pressed and released (to be extended)
|
|
145
|
+
* @returns {boolean} return false if we need to stop propagating the event
|
|
146
|
+
*/
|
|
147
|
+
onRelease() {
|
|
148
|
+
return false;
|
|
149
|
+
}
|
|
150
|
+
|
|
151
|
+
/**
|
|
152
|
+
* function callback for the tap and hold timer event
|
|
153
|
+
* @ignore
|
|
154
|
+
*/
|
|
155
|
+
hold() {
|
|
156
|
+
timer.clearTimeout(this.holdTimeout);
|
|
157
|
+
this.dirty = true;
|
|
158
|
+
if (!this.released) {
|
|
159
|
+
this.onHold();
|
|
160
|
+
}
|
|
161
|
+
}
|
|
162
|
+
|
|
163
|
+
/**
|
|
164
|
+
* function called when the object is pressed and held<br>
|
|
165
|
+
* to be extended <br>
|
|
166
|
+
*/
|
|
167
|
+
onHold() {}
|
|
168
|
+
|
|
169
|
+
/**
|
|
170
|
+
* function called when added to the game world or a container
|
|
171
|
+
* @ignore
|
|
172
|
+
*/
|
|
173
|
+
onActivateEvent() {
|
|
174
|
+
// register pointer events
|
|
175
|
+
registerPointerEvent(
|
|
176
|
+
"pointerdown",
|
|
177
|
+
this,
|
|
178
|
+
this.clicked.bind(this)
|
|
179
|
+
);
|
|
180
|
+
registerPointerEvent("pointerup", this, this.release.bind(this));
|
|
181
|
+
registerPointerEvent(
|
|
182
|
+
"pointercancel",
|
|
183
|
+
this,
|
|
184
|
+
this.release.bind(this)
|
|
185
|
+
);
|
|
186
|
+
registerPointerEvent("pointerenter", this, this.enter.bind(this));
|
|
187
|
+
registerPointerEvent("pointerleave", this, this.leave.bind(this));
|
|
188
|
+
}
|
|
189
|
+
|
|
190
|
+
/**
|
|
191
|
+
* function called when removed from the game world or a container
|
|
192
|
+
* @ignore
|
|
193
|
+
*/
|
|
194
|
+
onDeactivateEvent() {
|
|
195
|
+
// release pointer events
|
|
196
|
+
releasePointerEvent("pointerdown", this.hitbox);
|
|
197
|
+
releasePointerEvent("pointerup", this);
|
|
198
|
+
releasePointerEvent("pointercancel", this);
|
|
199
|
+
releasePointerEvent("pointerenter", this);
|
|
200
|
+
releasePointerEvent("pointerleave", this);
|
|
201
|
+
timer.clearTimeout(this.holdTimeout);
|
|
202
|
+
}
|
|
203
|
+
}
|
|
204
|
+
export default UIBaseElement;
|