melonjs 13.4.0 → 14.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +4 -6
- package/dist/melonjs.module.d.ts +13108 -11652
- package/dist/melonjs.module.js +581 -128
- 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 +1 -1
- package/src/physics/detector.js +3 -3
- package/src/physics/quadtree.js +2 -2
- 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/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;
|
|
@@ -1,24 +1,20 @@
|
|
|
1
|
-
import timer from "
|
|
2
|
-
import Sprite from "
|
|
3
|
-
import { registerPointerEvent, releasePointerEvent} from "
|
|
4
|
-
|
|
1
|
+
import timer from "./../../system/timer.js";
|
|
2
|
+
import Sprite from "./../sprite.js";
|
|
3
|
+
import { registerPointerEvent, releasePointerEvent} from "./../../input/input.js";
|
|
5
4
|
|
|
6
5
|
/**
|
|
7
6
|
* @classdesc
|
|
8
|
-
*
|
|
9
|
-
* A very basic object to manage GUI elements <br>
|
|
10
|
-
* The object simply register on the "pointerdown" <br>
|
|
11
|
-
* or "touchstart" event and call the onClick function"
|
|
7
|
+
* This is a basic sprite based button which you can use in your Game UI.
|
|
12
8
|
* @augments Sprite
|
|
13
9
|
*/
|
|
14
|
-
class
|
|
10
|
+
class UISpriteElement extends Sprite {
|
|
15
11
|
/**
|
|
16
12
|
* @param {number} x the x coordinate of the GUI Object
|
|
17
13
|
* @param {number} y the y coordinate of the GUI Object
|
|
18
14
|
* @param {object} settings See {@link Sprite}
|
|
19
15
|
* @example
|
|
20
16
|
* // create a basic GUI Object
|
|
21
|
-
* class myButton extends
|
|
17
|
+
* class myButton extends UISpriteElement {
|
|
22
18
|
* constructor(x, y) {
|
|
23
19
|
* var settings = {}
|
|
24
20
|
* settings.image = "button";
|
|
@@ -49,10 +45,8 @@ class GUI_Object extends Sprite {
|
|
|
49
45
|
|
|
50
46
|
/**
|
|
51
47
|
* object can be clicked or not
|
|
52
|
-
* @public
|
|
53
48
|
* @type {boolean}
|
|
54
49
|
* @default true
|
|
55
|
-
* @name GUI_Object#isClickable
|
|
56
50
|
*/
|
|
57
51
|
this.isClickable = true;
|
|
58
52
|
|
|
@@ -60,25 +54,20 @@ class GUI_Object extends Sprite {
|
|
|
60
54
|
* Tap and hold threshold timeout in ms
|
|
61
55
|
* @type {number}
|
|
62
56
|
* @default 250
|
|
63
|
-
* @name GUI_Object#holdThreshold
|
|
64
57
|
*/
|
|
65
58
|
this.holdThreshold = 250;
|
|
66
59
|
|
|
67
60
|
/**
|
|
68
61
|
* object can be tap and hold
|
|
69
|
-
* @public
|
|
70
62
|
* @type {boolean}
|
|
71
63
|
* @default false
|
|
72
|
-
* @name GUI_Object#isHoldable
|
|
73
64
|
*/
|
|
74
65
|
this.isHoldable = false;
|
|
75
66
|
|
|
76
67
|
/**
|
|
77
68
|
* true if the pointer is over the object
|
|
78
|
-
* @public
|
|
79
69
|
* @type {boolean}
|
|
80
70
|
* @default false
|
|
81
|
-
* @name GUI_Object#hover
|
|
82
71
|
*/
|
|
83
72
|
this.hover = false;
|
|
84
73
|
|
|
@@ -115,9 +104,6 @@ class GUI_Object extends Sprite {
|
|
|
115
104
|
|
|
116
105
|
/**
|
|
117
106
|
* function called when the object is pressed (to be extended)
|
|
118
|
-
* @name onClick
|
|
119
|
-
* @memberof GUI_Object
|
|
120
|
-
* @public
|
|
121
107
|
* @param {Pointer} event the event object
|
|
122
108
|
* @returns {boolean} return false if we need to stop propagating the event
|
|
123
109
|
*/
|
|
@@ -137,9 +123,6 @@ class GUI_Object extends Sprite {
|
|
|
137
123
|
|
|
138
124
|
/**
|
|
139
125
|
* function called when the pointer is over the object
|
|
140
|
-
* @name onOver
|
|
141
|
-
* @memberof GUI_Object
|
|
142
|
-
* @public
|
|
143
126
|
* @param {Pointer} event the event object
|
|
144
127
|
*/
|
|
145
128
|
onOver(event) { // eslint-disable-line no-unused-vars
|
|
@@ -159,9 +142,6 @@ class GUI_Object extends Sprite {
|
|
|
159
142
|
|
|
160
143
|
/**
|
|
161
144
|
* function called when the pointer is leaving the object area
|
|
162
|
-
* @name onOut
|
|
163
|
-
* @memberof GUI_Object
|
|
164
|
-
* @public
|
|
165
145
|
* @param {Pointer} event the event object
|
|
166
146
|
*/
|
|
167
147
|
onOut(event) { // eslint-disable-line no-unused-vars
|
|
@@ -183,9 +163,6 @@ class GUI_Object extends Sprite {
|
|
|
183
163
|
|
|
184
164
|
/**
|
|
185
165
|
* function called when the object is pressed and released (to be extended)
|
|
186
|
-
* @name onRelease
|
|
187
|
-
* @memberof GUI_Object
|
|
188
|
-
* @public
|
|
189
166
|
* @returns {boolean} return false if we need to stop propagating the event
|
|
190
167
|
*/
|
|
191
168
|
onRelease() {
|
|
@@ -207,9 +184,6 @@ class GUI_Object extends Sprite {
|
|
|
207
184
|
/**
|
|
208
185
|
* function called when the object is pressed and held<br>
|
|
209
186
|
* to be extended <br>
|
|
210
|
-
* @name onHold
|
|
211
|
-
* @memberof GUI_Object
|
|
212
|
-
* @public
|
|
213
187
|
*/
|
|
214
188
|
onHold() {}
|
|
215
189
|
|
|
@@ -239,6 +213,5 @@ class GUI_Object extends Sprite {
|
|
|
239
213
|
releasePointerEvent("pointerleave", this);
|
|
240
214
|
timer.clearTimeout(this.holdTimeout);
|
|
241
215
|
}
|
|
242
|
-
}
|
|
243
|
-
|
|
244
|
-
export default GUI_Object;
|
|
216
|
+
}
|
|
217
|
+
export default UISpriteElement;
|
|
@@ -0,0 +1,121 @@
|
|
|
1
|
+
import Vector2d from "../../math/vector2.js";
|
|
2
|
+
import BitmapText from "../../text/bitmaptext.js";
|
|
3
|
+
import RoundRect from "../../geometries/roundrect.js";
|
|
4
|
+
import UIBaseElement from "./uibaseelement.js";
|
|
5
|
+
|
|
6
|
+
|
|
7
|
+
/**
|
|
8
|
+
* @classdesc
|
|
9
|
+
* This is a basic base text button which you can use in your Game UI.
|
|
10
|
+
* @augments UIBaseElement
|
|
11
|
+
*/
|
|
12
|
+
class UITextButton extends UIBaseElement {
|
|
13
|
+
/**
|
|
14
|
+
* A Text Button with an outlined background border, filled with background color.
|
|
15
|
+
* It uses a RoundRect as background and changes the background color on hovering over.
|
|
16
|
+
* The background will be drawn with 0.5 opacity, so that the background of the button is
|
|
17
|
+
* slightly shining through.
|
|
18
|
+
* @param {number} x x pos of the button
|
|
19
|
+
* @param {number} y y pos of the button
|
|
20
|
+
* @param {string} [settings.font] The name of the BitmapText font to use
|
|
21
|
+
* @param {number} [settings.size] The scale factor of the font (default: 1)
|
|
22
|
+
* @param {string} [settings.text] The text to display (default: 'click me')
|
|
23
|
+
* @param {string} [settings.bindKey] The key to bind the action to (default: none)
|
|
24
|
+
* @param {string} [settings.backgroundColor] The css value of a background color
|
|
25
|
+
* @param {string} [settings.hoverColor] The css value of a color to be used if the pointer hovers over the button
|
|
26
|
+
* @param {string} [settings.borderStrokeColor] The css value of a color to be used to draw the border
|
|
27
|
+
* @param {boolean} [settings.offScreenCanvas] Weather to use an offScreen canvas or not
|
|
28
|
+
* @param {string} [settings.fillStyle] The css value of a tint color to be used to tint the text
|
|
29
|
+
* @param {number} [settings.borderWidth] Width of the button
|
|
30
|
+
* @param {number} [settings.borderHeight] Height of the button
|
|
31
|
+
* @example
|
|
32
|
+
* // Create a new Button
|
|
33
|
+
* class PlayButton extends BaseTextButton {
|
|
34
|
+
* constructor(x,y) {
|
|
35
|
+
* super(x,y, {
|
|
36
|
+
* font: 'my-font',
|
|
37
|
+
* text: 'Play',
|
|
38
|
+
* // if you omit the next two, size is calculated by the size of the text
|
|
39
|
+
* borderWidth: 200,
|
|
40
|
+
* borderHeight: 20,
|
|
41
|
+
* });
|
|
42
|
+
* }
|
|
43
|
+
*
|
|
44
|
+
* onClick(){
|
|
45
|
+
* state.change(state.PLAY);
|
|
46
|
+
* }
|
|
47
|
+
* }
|
|
48
|
+
*
|
|
49
|
+
* game.world.addChild(new PlayButton(15,200));
|
|
50
|
+
*/
|
|
51
|
+
constructor(x, y, settings) {
|
|
52
|
+
super(x, y);
|
|
53
|
+
settings.font = settings.font || "24Outline";
|
|
54
|
+
settings.size = settings.size || 1;
|
|
55
|
+
settings.text = settings.text || "<Click Me>";
|
|
56
|
+
settings.bindKey = settings.bindKey || -1;
|
|
57
|
+
settings.backgroundColor = settings.backgroundColor || "#00aa00";
|
|
58
|
+
settings.hoverColor = settings.hoverColor || "#00ff00";
|
|
59
|
+
settings.borderStrokeColor = settings.borderStrokeColor || "#000000";
|
|
60
|
+
settings.offScreenCanvas = settings.offScreenCanvas || false;
|
|
61
|
+
settings.fillStyle = settings.fillStyle || "#ffffff";
|
|
62
|
+
settings.lineWidth = settings.lineWidth || 1;
|
|
63
|
+
settings.anchorPoint = settings.anchorPoint || new Vector2d(0, 0);
|
|
64
|
+
|
|
65
|
+
let font = new BitmapText(x, y, settings);
|
|
66
|
+
let dimensions = font.measureText();
|
|
67
|
+
settings.borderWidth = settings.borderWidth || dimensions.width + 16;
|
|
68
|
+
settings.borderHeight = settings.borderHeight || dimensions.height + 16;
|
|
69
|
+
|
|
70
|
+
let border = new RoundRect(
|
|
71
|
+
x,
|
|
72
|
+
y,
|
|
73
|
+
settings.borderWidth,
|
|
74
|
+
settings.borderHeight
|
|
75
|
+
);
|
|
76
|
+
super.setShape(
|
|
77
|
+
x,
|
|
78
|
+
y,
|
|
79
|
+
border.getBounds().width,
|
|
80
|
+
border.getBounds().height
|
|
81
|
+
);
|
|
82
|
+
|
|
83
|
+
// build up
|
|
84
|
+
this.font = font;
|
|
85
|
+
this.dimensions = dimensions;
|
|
86
|
+
this.border = border;
|
|
87
|
+
this.settings = settings;
|
|
88
|
+
|
|
89
|
+
// adjust text position
|
|
90
|
+
this.font.pos.set(
|
|
91
|
+
Math.round((border.width - dimensions.width) / 2) + this.font.pos.x,
|
|
92
|
+
Math.round((border.height - dimensions.height) / 2) +
|
|
93
|
+
this.font.pos.y
|
|
94
|
+
);
|
|
95
|
+
}
|
|
96
|
+
|
|
97
|
+
draw(renderer) {
|
|
98
|
+
renderer.setGlobalAlpha(0.5);
|
|
99
|
+
if (!this.hover) {
|
|
100
|
+
renderer.setColor(this.settings.backgroundColor);
|
|
101
|
+
} else {
|
|
102
|
+
renderer.setColor(this.settings.hoverColor);
|
|
103
|
+
}
|
|
104
|
+
|
|
105
|
+
renderer.fill(this.border);
|
|
106
|
+
renderer.setGlobalAlpha(1);
|
|
107
|
+
renderer.setColor(this.settings.borderStrokeColor);
|
|
108
|
+
renderer.stroke(this.border);
|
|
109
|
+
|
|
110
|
+
// fix: supporting tint
|
|
111
|
+
renderer.setTint(this.font.tint, this.font.getOpacity());
|
|
112
|
+
this.font.draw(
|
|
113
|
+
renderer,
|
|
114
|
+
this.settings.text,
|
|
115
|
+
this.font.pos.x,
|
|
116
|
+
this.font.pos.y
|
|
117
|
+
);
|
|
118
|
+
}
|
|
119
|
+
}
|
|
120
|
+
export default UITextButton;
|
|
121
|
+
|
package/src/state/stage.js
CHANGED
|
@@ -125,17 +125,17 @@ class Stage {
|
|
|
125
125
|
|
|
126
126
|
// update the camera/viewport
|
|
127
127
|
// iterate through all cameras
|
|
128
|
-
this.cameras.forEach(
|
|
128
|
+
this.cameras.forEach((camera) => {
|
|
129
129
|
if (camera.update(dt) === true) {
|
|
130
130
|
isDirty = true;
|
|
131
|
-
}
|
|
131
|
+
}
|
|
132
132
|
});
|
|
133
133
|
|
|
134
134
|
// update all lights
|
|
135
135
|
this.lights.forEach((light) => {
|
|
136
136
|
if (light.update(dt) === true) {
|
|
137
137
|
isDirty = true;
|
|
138
|
-
}
|
|
138
|
+
}
|
|
139
139
|
});
|
|
140
140
|
|
|
141
141
|
return isDirty;
|
|
@@ -224,6 +224,5 @@ class Stage {
|
|
|
224
224
|
this.settings.onDestroyEvent.apply(this, arguments);
|
|
225
225
|
}
|
|
226
226
|
}
|
|
227
|
-
}
|
|
228
|
-
|
|
227
|
+
}
|
|
229
228
|
export default Stage;
|