melonjs 9.1.0 → 10.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/{LICENSE → LICENSE.md} +0 -0
- package/README.md +93 -57
- package/dist/melonjs.js +10334 -11179
- package/dist/melonjs.min.js +4 -10
- package/dist/melonjs.module.d.ts +13206 -0
- package/dist/melonjs.module.js +9913 -10872
- package/package.json +19 -14
- package/src/audio/audio.js +477 -553
- package/src/camera/camera2d.js +67 -65
- package/src/entity/draggable.js +26 -35
- package/src/entity/droptarget.js +17 -14
- package/src/entity/entity.js +59 -79
- package/src/game.js +194 -204
- package/src/index.js +12 -30
- package/src/input/gamepad.js +8 -19
- package/src/input/keyboard.js +4 -4
- package/src/input/pointer.js +14 -12
- package/src/input/pointerevent.js +15 -13
- package/src/lang/deprecated.js +2 -887
- package/src/level/level.js +3 -3
- package/src/level/tiled/TMXGroup.js +7 -11
- package/src/level/tiled/TMXLayer.js +33 -32
- package/src/level/tiled/TMXTileMap.js +15 -19
- package/src/level/tiled/TMXTileset.js +5 -5
- package/src/level/tiled/TMXUtils.js +3 -3
- package/src/level/tiled/renderer/TMXRenderer.js +4 -0
- package/src/loader/loader.js +8 -23
- package/src/loader/loadingscreen.js +51 -60
- package/src/math/matrix3.js +1 -1
- package/src/particles/emitter.js +36 -39
- package/src/particles/particle.js +27 -12
- package/src/particles/particlecontainer.js +17 -16
- package/src/physics/body.js +80 -118
- package/src/physics/collision.js +5 -235
- package/src/physics/detector.js +235 -0
- package/src/physics/quadtree.js +14 -14
- package/src/physics/world.js +84 -18
- package/src/plugin/plugin.js +26 -24
- package/src/polyfill/console.js +9 -14
- package/src/renderable/GUI.js +48 -62
- package/src/renderable/collectable.js +11 -4
- package/src/renderable/colorlayer.js +28 -26
- package/src/renderable/container.js +120 -96
- package/src/renderable/imagelayer.js +94 -93
- package/src/renderable/renderable.js +164 -138
- package/src/renderable/sprite.js +42 -44
- package/src/renderable/trigger.js +24 -17
- package/src/shapes/ellipse.js +27 -27
- package/src/shapes/line.js +12 -8
- package/src/shapes/poly.js +77 -49
- package/src/shapes/rectangle.js +193 -268
- package/src/state/stage.js +23 -25
- package/src/state/state.js +35 -86
- package/src/system/device.js +233 -285
- package/src/system/event.js +485 -432
- package/src/system/pooling.js +61 -54
- package/src/system/save.js +17 -16
- package/src/system/timer.js +34 -38
- package/src/text/bitmaptext.js +44 -46
- package/src/text/text.js +39 -34
- package/src/tweens/easing.js +0 -2
- package/src/tweens/interpolation.js +3 -8
- package/src/tweens/tween.js +332 -351
- package/src/utils/function.js +6 -8
- package/src/utils/utils.js +34 -30
- package/src/video/canvas/canvas_renderer.js +13 -8
- package/src/video/renderer.js +8 -7
- package/src/video/texture.js +8 -8
- package/src/video/texture_cache.js +5 -5
- package/src/video/video.js +373 -403
- package/src/video/webgl/glshader.js +2 -2
- package/src/video/webgl/webgl_compositor.js +14 -8
- package/src/video/webgl/webgl_renderer.js +21 -19
- package/plugins/debug/debugPanel.js +0 -770
- package/plugins/debug/font/PressStart2P.fnt +0 -100
- package/plugins/debug/font/PressStart2P.ltr +0 -1
- package/plugins/debug/font/PressStart2P.png +0 -0
- package/plugins/debug/particleDebugPanel.js +0 -303
package/src/camera/camera2d.js
CHANGED
|
@@ -5,12 +5,12 @@ import ObservableVector3d from "./../math/observable_vector3.js";
|
|
|
5
5
|
import Matrix2d from "./../math/matrix2.js";
|
|
6
6
|
import Matrix3d from "./../math/matrix3.js";
|
|
7
7
|
import Rect from "./../shapes/rectangle.js";
|
|
8
|
-
import
|
|
9
|
-
import event from "./../system/event.js";
|
|
8
|
+
import { renderer } from "./../video/video.js";
|
|
9
|
+
import * as event from "./../system/event.js";
|
|
10
10
|
import pool from "./../system/pooling.js";
|
|
11
11
|
import Renderable from "./../renderable/renderable.js";
|
|
12
12
|
import {clamp, toBeCloseTo} from "./../math/math.js";
|
|
13
|
-
import
|
|
13
|
+
import { world } from "./../game.js";
|
|
14
14
|
|
|
15
15
|
|
|
16
16
|
// some ref shortcut
|
|
@@ -30,12 +30,13 @@ var targetV = new Vector2d();
|
|
|
30
30
|
* @param {Number} maxX end x offset
|
|
31
31
|
* @param {Number} maxY end y offset
|
|
32
32
|
*/
|
|
33
|
-
|
|
33
|
+
class Camera2d extends Renderable {
|
|
34
|
+
|
|
34
35
|
/**
|
|
35
36
|
* @ignore
|
|
36
37
|
*/
|
|
37
|
-
|
|
38
|
-
|
|
38
|
+
constructor(minX, minY, maxX, maxY) {
|
|
39
|
+
super(minX, minY, maxX - minX, maxY - minY);
|
|
39
40
|
|
|
40
41
|
/**
|
|
41
42
|
* Axis definition
|
|
@@ -172,21 +173,21 @@ var Camera2d = Renderable.extend({
|
|
|
172
173
|
this._updateProjectionMatrix();
|
|
173
174
|
|
|
174
175
|
// subscribe to the game reset event
|
|
175
|
-
event.
|
|
176
|
+
event.on(event.GAME_RESET, this.reset, this);
|
|
176
177
|
// subscribe to the canvas resize event
|
|
177
|
-
event.
|
|
178
|
-
}
|
|
178
|
+
event.on(event.CANVAS_ONRESIZE, this.resize, this);
|
|
179
|
+
}
|
|
179
180
|
|
|
180
181
|
// -- some private function ---
|
|
181
182
|
|
|
182
183
|
/** @ignore */
|
|
183
184
|
// update the projection matrix based on the projection frame (a rectangle)
|
|
184
|
-
_updateProjectionMatrix
|
|
185
|
+
_updateProjectionMatrix() {
|
|
185
186
|
this.projectionMatrix.ortho(0, this.width, this.height, 0, this.near, this.far);
|
|
186
|
-
}
|
|
187
|
+
}
|
|
187
188
|
|
|
188
189
|
/** @ignore */
|
|
189
|
-
_followH
|
|
190
|
+
_followH(target) {
|
|
190
191
|
var targetX = this.pos.x;
|
|
191
192
|
if ((target.x - this.pos.x) > (this.deadzone.right)) {
|
|
192
193
|
targetX = MIN((target.x) - (this.deadzone.right), this.bounds.width - this.width);
|
|
@@ -196,10 +197,10 @@ var Camera2d = Renderable.extend({
|
|
|
196
197
|
}
|
|
197
198
|
return targetX;
|
|
198
199
|
|
|
199
|
-
}
|
|
200
|
+
}
|
|
200
201
|
|
|
201
202
|
/** @ignore */
|
|
202
|
-
_followV
|
|
203
|
+
_followV(target) {
|
|
203
204
|
var targetY = this.pos.y;
|
|
204
205
|
if ((target.y - this.pos.y) > (this.deadzone.bottom)) {
|
|
205
206
|
targetY = MIN((target.y) - (this.deadzone.bottom), this.bounds.height - this.height);
|
|
@@ -208,7 +209,7 @@ var Camera2d = Renderable.extend({
|
|
|
208
209
|
targetY = MAX((target.y) - this.deadzone.pos.y, this.bounds.top);
|
|
209
210
|
}
|
|
210
211
|
return targetY;
|
|
211
|
-
}
|
|
212
|
+
}
|
|
212
213
|
|
|
213
214
|
// -- public function ---
|
|
214
215
|
|
|
@@ -220,7 +221,7 @@ var Camera2d = Renderable.extend({
|
|
|
220
221
|
* @param {Number} [x=0]
|
|
221
222
|
* @param {Number} [y=0]
|
|
222
223
|
*/
|
|
223
|
-
reset
|
|
224
|
+
reset(x, y) {
|
|
224
225
|
// reset the initial camera position to 0,0
|
|
225
226
|
this.pos.x = x || 0;
|
|
226
227
|
this.pos.y = y || 0;
|
|
@@ -238,7 +239,7 @@ var Camera2d = Renderable.extend({
|
|
|
238
239
|
|
|
239
240
|
// update the projection matrix
|
|
240
241
|
this._updateProjectionMatrix();
|
|
241
|
-
}
|
|
242
|
+
}
|
|
242
243
|
|
|
243
244
|
/**
|
|
244
245
|
* change the deadzone settings.
|
|
@@ -251,7 +252,7 @@ var Camera2d = Renderable.extend({
|
|
|
251
252
|
* @param {Number} w deadzone width
|
|
252
253
|
* @param {Number} h deadzone height
|
|
253
254
|
*/
|
|
254
|
-
setDeadzone
|
|
255
|
+
setDeadzone(w, h) {
|
|
255
256
|
if (typeof(this.deadzone) === "undefined") {
|
|
256
257
|
this.deadzone = new Rect(0, 0, 0, 0);
|
|
257
258
|
}
|
|
@@ -269,8 +270,7 @@ var Camera2d = Renderable.extend({
|
|
|
269
270
|
this.updateTarget();
|
|
270
271
|
|
|
271
272
|
this.smoothFollow = true;
|
|
272
|
-
}
|
|
273
|
-
|
|
273
|
+
}
|
|
274
274
|
|
|
275
275
|
/**
|
|
276
276
|
* resize the camera
|
|
@@ -281,9 +281,9 @@ var Camera2d = Renderable.extend({
|
|
|
281
281
|
* @param {Number} h new height of the camera
|
|
282
282
|
* @return {me.Camera2d} this camera
|
|
283
283
|
*/
|
|
284
|
-
resize
|
|
284
|
+
resize(w, h) {
|
|
285
285
|
// parent consctructor, resize camera rect
|
|
286
|
-
|
|
286
|
+
super.resize(w, h);
|
|
287
287
|
|
|
288
288
|
// disable damping while resizing
|
|
289
289
|
this.smoothFollow = false;
|
|
@@ -298,10 +298,10 @@ var Camera2d = Renderable.extend({
|
|
|
298
298
|
this._updateProjectionMatrix();
|
|
299
299
|
|
|
300
300
|
// publish the viewport resize event
|
|
301
|
-
event.
|
|
301
|
+
event.emit(event.VIEWPORT_ONRESIZE, this.width, this.height);
|
|
302
302
|
|
|
303
303
|
return this;
|
|
304
|
-
}
|
|
304
|
+
}
|
|
305
305
|
|
|
306
306
|
/**
|
|
307
307
|
* set the camera boundaries (set to the world limit by default).
|
|
@@ -314,13 +314,13 @@ var Camera2d = Renderable.extend({
|
|
|
314
314
|
* @param {Number} w world width limit
|
|
315
315
|
* @param {Number} h world height limit
|
|
316
316
|
*/
|
|
317
|
-
setBounds
|
|
317
|
+
setBounds(x, y, w, h) {
|
|
318
318
|
this.smoothFollow = false;
|
|
319
319
|
this.bounds.setMinMax(x, y, w + x, h + y);
|
|
320
320
|
this.moveTo(this.pos.x, this.pos.y);
|
|
321
321
|
this.update();
|
|
322
322
|
this.smoothFollow = true;
|
|
323
|
-
}
|
|
323
|
+
}
|
|
324
324
|
|
|
325
325
|
/**
|
|
326
326
|
* set the camera to follow the specified renderable. <br>
|
|
@@ -335,7 +335,7 @@ var Camera2d = Renderable.extend({
|
|
|
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);
|
|
337
337
|
*/
|
|
338
|
-
follow
|
|
338
|
+
follow(target, axis, damping) {
|
|
339
339
|
if (target instanceof Renderable) {
|
|
340
340
|
this.target = target.pos;
|
|
341
341
|
}
|
|
@@ -363,7 +363,7 @@ var Camera2d = Renderable.extend({
|
|
|
363
363
|
this.updateTarget();
|
|
364
364
|
|
|
365
365
|
this.smoothFollow = true;
|
|
366
|
-
}
|
|
366
|
+
}
|
|
367
367
|
|
|
368
368
|
/**
|
|
369
369
|
* unfollow the current target
|
|
@@ -371,10 +371,10 @@ var Camera2d = Renderable.extend({
|
|
|
371
371
|
* @memberOf me.Camera2d
|
|
372
372
|
* @function
|
|
373
373
|
*/
|
|
374
|
-
unfollow
|
|
374
|
+
unfollow() {
|
|
375
375
|
this.target = null;
|
|
376
376
|
this.follow_axis = this.AXIS.NONE;
|
|
377
|
-
}
|
|
377
|
+
}
|
|
378
378
|
|
|
379
379
|
/**
|
|
380
380
|
* move the camera upper-left position by the specified offset.
|
|
@@ -388,9 +388,9 @@ var Camera2d = Renderable.extend({
|
|
|
388
388
|
* // Move the camera up by four pixels
|
|
389
389
|
* me.game.viewport.move(0, -4);
|
|
390
390
|
*/
|
|
391
|
-
move
|
|
391
|
+
move(x, y) {
|
|
392
392
|
this.moveTo(this.pos.x + x, this.pos.y + y);
|
|
393
|
-
}
|
|
393
|
+
}
|
|
394
394
|
|
|
395
395
|
/**
|
|
396
396
|
* move the camera upper-left position to the specified coordinates
|
|
@@ -401,7 +401,7 @@ var Camera2d = Renderable.extend({
|
|
|
401
401
|
* @param {Number} x
|
|
402
402
|
* @param {Number} y
|
|
403
403
|
*/
|
|
404
|
-
moveTo
|
|
404
|
+
moveTo(x, y) {
|
|
405
405
|
var _x = this.pos.x;
|
|
406
406
|
var _y = this.pos.y;
|
|
407
407
|
|
|
@@ -418,12 +418,12 @@ var Camera2d = Renderable.extend({
|
|
|
418
418
|
|
|
419
419
|
//publish the VIEWPORT_ONCHANGE event if necessary
|
|
420
420
|
if (_x !== this.pos.x || _y !== this.pos.y) {
|
|
421
|
-
event.
|
|
421
|
+
event.emit(event.VIEWPORT_ONCHANGE, this.pos);
|
|
422
422
|
}
|
|
423
|
-
}
|
|
423
|
+
}
|
|
424
424
|
|
|
425
425
|
/** @ignore */
|
|
426
|
-
updateTarget
|
|
426
|
+
updateTarget() {
|
|
427
427
|
if (this.target) {
|
|
428
428
|
|
|
429
429
|
targetV.setV(this.pos);
|
|
@@ -468,10 +468,10 @@ var Camera2d = Renderable.extend({
|
|
|
468
468
|
}
|
|
469
469
|
}
|
|
470
470
|
return false;
|
|
471
|
-
}
|
|
471
|
+
}
|
|
472
472
|
|
|
473
473
|
/** @ignore */
|
|
474
|
-
update
|
|
474
|
+
update(dt) {
|
|
475
475
|
var updated = this.updateTarget(dt);
|
|
476
476
|
|
|
477
477
|
if (this._shake.duration > 0) {
|
|
@@ -499,7 +499,7 @@ var Camera2d = Renderable.extend({
|
|
|
499
499
|
|
|
500
500
|
if (updated === true) {
|
|
501
501
|
//publish the corresponding message
|
|
502
|
-
event.
|
|
502
|
+
event.emit(event.VIEWPORT_ONCHANGE, this.pos);
|
|
503
503
|
}
|
|
504
504
|
|
|
505
505
|
// check for fade/flash effect
|
|
@@ -514,7 +514,7 @@ var Camera2d = Renderable.extend({
|
|
|
514
514
|
this.invCurrentTransform.identity();
|
|
515
515
|
}
|
|
516
516
|
return updated;
|
|
517
|
-
}
|
|
517
|
+
}
|
|
518
518
|
|
|
519
519
|
/**
|
|
520
520
|
* shake the camera
|
|
@@ -532,14 +532,14 @@ var Camera2d = Renderable.extend({
|
|
|
532
532
|
* // shake it baby !
|
|
533
533
|
* me.game.viewport.shake(10, 500, me.game.viewport.AXIS.BOTH);
|
|
534
534
|
*/
|
|
535
|
-
shake
|
|
535
|
+
shake(intensity, duration, axis, onComplete, force) {
|
|
536
536
|
if (this._shake.duration === 0 || force === true) {
|
|
537
537
|
this._shake.intensity = intensity;
|
|
538
538
|
this._shake.duration = duration;
|
|
539
539
|
this._shake.axis = axis || this.AXIS.BOTH;
|
|
540
540
|
this._shake.onComplete = typeof (onComplete) === "function" ? onComplete : undefined;
|
|
541
541
|
}
|
|
542
|
-
}
|
|
542
|
+
}
|
|
543
543
|
|
|
544
544
|
/**
|
|
545
545
|
* fadeOut(flash) effect<p>
|
|
@@ -558,14 +558,14 @@ var Camera2d = Renderable.extend({
|
|
|
558
558
|
* me.game.viewport.fadeOut("#fff", 150);
|
|
559
559
|
* });
|
|
560
560
|
*/
|
|
561
|
-
fadeOut
|
|
561
|
+
fadeOut(color, duration = 1000, onComplete) {
|
|
562
562
|
this._fadeOut.color = pool.pull("Color").copy(color);
|
|
563
563
|
this._fadeOut.tween = pool.pull("Tween", this._fadeOut.color)
|
|
564
564
|
.to({ alpha: 0.0 }, duration)
|
|
565
565
|
.onComplete(onComplete || null);
|
|
566
566
|
this._fadeOut.tween.isPersistent = true;
|
|
567
567
|
this._fadeOut.tween.start();
|
|
568
|
-
}
|
|
568
|
+
}
|
|
569
569
|
|
|
570
570
|
/**
|
|
571
571
|
* fadeIn effect <p>
|
|
@@ -580,7 +580,7 @@ var Camera2d = Renderable.extend({
|
|
|
580
580
|
* // flash the camera to white for 75ms
|
|
581
581
|
* me.game.viewport.fadeIn("#FFFFFF", 75);
|
|
582
582
|
*/
|
|
583
|
-
fadeIn
|
|
583
|
+
fadeIn(color, duration = 1000, onComplete) {
|
|
584
584
|
this._fadeIn.color = pool.pull("Color").copy(color);
|
|
585
585
|
var _alpha = this._fadeIn.color.alpha;
|
|
586
586
|
this._fadeIn.color.alpha = 0.0;
|
|
@@ -589,7 +589,7 @@ var Camera2d = Renderable.extend({
|
|
|
589
589
|
.onComplete(onComplete || null);
|
|
590
590
|
this._fadeIn.tween.isPersistent = true;
|
|
591
591
|
this._fadeIn.tween.start();
|
|
592
|
-
}
|
|
592
|
+
}
|
|
593
593
|
|
|
594
594
|
/**
|
|
595
595
|
* return the camera width
|
|
@@ -598,9 +598,9 @@ var Camera2d = Renderable.extend({
|
|
|
598
598
|
* @function
|
|
599
599
|
* @return {Number}
|
|
600
600
|
*/
|
|
601
|
-
getWidth
|
|
601
|
+
getWidth() {
|
|
602
602
|
return this.width;
|
|
603
|
-
}
|
|
603
|
+
}
|
|
604
604
|
|
|
605
605
|
/**
|
|
606
606
|
* return the camera height
|
|
@@ -609,9 +609,9 @@ var Camera2d = Renderable.extend({
|
|
|
609
609
|
* @function
|
|
610
610
|
* @return {Number}
|
|
611
611
|
*/
|
|
612
|
-
getHeight
|
|
612
|
+
getHeight() {
|
|
613
613
|
return this.height;
|
|
614
|
-
}
|
|
614
|
+
}
|
|
615
615
|
|
|
616
616
|
/**
|
|
617
617
|
* set the camera position around the specified object
|
|
@@ -620,13 +620,13 @@ var Camera2d = Renderable.extend({
|
|
|
620
620
|
* @function
|
|
621
621
|
* @param {me.Renderable}
|
|
622
622
|
*/
|
|
623
|
-
focusOn
|
|
623
|
+
focusOn(target) {
|
|
624
624
|
var bounds = target.getBounds();
|
|
625
625
|
this.moveTo(
|
|
626
626
|
target.pos.x + bounds.left + (bounds.width / 2),
|
|
627
627
|
target.pos.y + bounds.top + (bounds.height / 2)
|
|
628
628
|
);
|
|
629
|
-
}
|
|
629
|
+
}
|
|
630
630
|
|
|
631
631
|
/**
|
|
632
632
|
* check if the specified renderable is in the camera
|
|
@@ -637,15 +637,15 @@ var Camera2d = Renderable.extend({
|
|
|
637
637
|
* @param {Boolean} [floating===object.floating] if visibility check should be done against screen coordinates
|
|
638
638
|
* @return {Boolean}
|
|
639
639
|
*/
|
|
640
|
-
isVisible
|
|
640
|
+
isVisible(obj, floating = obj.floating) {
|
|
641
641
|
if (floating === true || obj.floating === true) {
|
|
642
642
|
// check against screen coordinates
|
|
643
|
-
return
|
|
643
|
+
return renderer.overlaps(obj.getBounds());
|
|
644
644
|
} else {
|
|
645
645
|
// check if within the current camera
|
|
646
646
|
return obj.getBounds().overlaps(this);
|
|
647
647
|
}
|
|
648
|
-
}
|
|
648
|
+
}
|
|
649
649
|
|
|
650
650
|
/**
|
|
651
651
|
* convert the given "local" (screen) coordinates into world coordinates
|
|
@@ -658,15 +658,15 @@ var Camera2d = Renderable.extend({
|
|
|
658
658
|
* converted value
|
|
659
659
|
* @return {me.Vector2d}
|
|
660
660
|
*/
|
|
661
|
-
localToWorld
|
|
661
|
+
localToWorld(x, y, v) {
|
|
662
662
|
// TODO memoization for one set of coords (multitouch)
|
|
663
663
|
v = v || new Vector2d();
|
|
664
|
-
v.set(x, y).add(this.pos).sub(
|
|
664
|
+
v.set(x, y).add(this.pos).sub(world.pos);
|
|
665
665
|
if (!this.currentTransform.isIdentity()) {
|
|
666
666
|
this.invCurrentTransform.apply(v);
|
|
667
667
|
}
|
|
668
668
|
return v;
|
|
669
|
-
}
|
|
669
|
+
}
|
|
670
670
|
|
|
671
671
|
/**
|
|
672
672
|
* convert the given world coordinates into "local" (screen) coordinates
|
|
@@ -679,21 +679,21 @@ var Camera2d = Renderable.extend({
|
|
|
679
679
|
* converted value
|
|
680
680
|
* @return {me.Vector2d}
|
|
681
681
|
*/
|
|
682
|
-
worldToLocal
|
|
682
|
+
worldToLocal(x, y, v) {
|
|
683
683
|
// TODO memoization for one set of coords (multitouch)
|
|
684
684
|
v = v || new Vector2d();
|
|
685
685
|
v.set(x, y);
|
|
686
686
|
if (!this.currentTransform.isIdentity()) {
|
|
687
687
|
this.currentTransform.apply(v);
|
|
688
688
|
}
|
|
689
|
-
return v.sub(this.pos).add(
|
|
690
|
-
}
|
|
689
|
+
return v.sub(this.pos).add(world.pos);
|
|
690
|
+
}
|
|
691
691
|
|
|
692
692
|
/**
|
|
693
693
|
* render the camera effects
|
|
694
694
|
* @ignore
|
|
695
695
|
*/
|
|
696
|
-
drawFX
|
|
696
|
+
drawFX(renderer) {
|
|
697
697
|
// fading effect
|
|
698
698
|
if (this._fadeIn.tween) {
|
|
699
699
|
// add an overlay
|
|
@@ -727,13 +727,13 @@ var Camera2d = Renderable.extend({
|
|
|
727
727
|
this._fadeOut.color = null;
|
|
728
728
|
}
|
|
729
729
|
}
|
|
730
|
-
}
|
|
730
|
+
}
|
|
731
731
|
|
|
732
732
|
/**
|
|
733
733
|
* draw all object visibile in this viewport
|
|
734
734
|
* @ignore
|
|
735
735
|
*/
|
|
736
|
-
draw
|
|
736
|
+
draw(renderer, container) {
|
|
737
737
|
var translateX = this.pos.x + this.offset.x;
|
|
738
738
|
var translateY = this.pos.y + this.offset.y;
|
|
739
739
|
|
|
@@ -769,5 +769,7 @@ var Camera2d = Renderable.extend({
|
|
|
769
769
|
// translate the world coordinates by default to screen coordinates
|
|
770
770
|
container.currentTransform.translate(translateX, translateY);
|
|
771
771
|
}
|
|
772
|
-
|
|
772
|
+
|
|
773
|
+
};
|
|
774
|
+
|
|
773
775
|
export default Camera2d;
|
package/src/entity/draggable.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import Vector2d from "./../math/vector2.js";
|
|
2
2
|
import * as input from "./../input/input.js";
|
|
3
|
-
import event from "./../system/event.js";
|
|
3
|
+
import * as event from "./../system/event.js";
|
|
4
4
|
import Entity from "./entity.js";
|
|
5
5
|
|
|
6
6
|
/**
|
|
@@ -13,7 +13,8 @@ import Entity from "./entity.js";
|
|
|
13
13
|
* @param {Number} y the y coordinates of the entity object
|
|
14
14
|
* @param {Object} settings Entity properties (see {@link me.Entity})
|
|
15
15
|
*/
|
|
16
|
-
|
|
16
|
+
class DraggableEntity extends Entity {
|
|
17
|
+
|
|
17
18
|
/**
|
|
18
19
|
* Constructor
|
|
19
20
|
* @name init
|
|
@@ -23,15 +24,15 @@ var DraggableEntity = Entity.extend({
|
|
|
23
24
|
* @param {Number} y the y postion of the entity
|
|
24
25
|
* @param {Object} settings the additional entity settings
|
|
25
26
|
*/
|
|
26
|
-
|
|
27
|
-
|
|
27
|
+
constructor(x, y, settings) {
|
|
28
|
+
super(x, y, settings);
|
|
28
29
|
this.dragging = false;
|
|
29
30
|
this.dragId = null;
|
|
30
31
|
this.grabOffset = new Vector2d(0, 0);
|
|
31
32
|
this.onPointerEvent = input.registerPointerEvent;
|
|
32
33
|
this.removePointerEvent = input.releasePointerEvent;
|
|
33
34
|
this.initEvents();
|
|
34
|
-
}
|
|
35
|
+
}
|
|
35
36
|
|
|
36
37
|
/**
|
|
37
38
|
* Initializes the events the modules needs to listen to
|
|
@@ -43,8 +44,7 @@ var DraggableEntity = Entity.extend({
|
|
|
43
44
|
* @memberOf me.DraggableEntity
|
|
44
45
|
* @function
|
|
45
46
|
*/
|
|
46
|
-
initEvents
|
|
47
|
-
var self = this;
|
|
47
|
+
initEvents() {
|
|
48
48
|
/**
|
|
49
49
|
* @ignore
|
|
50
50
|
*/
|
|
@@ -60,18 +60,10 @@ var DraggableEntity = Entity.extend({
|
|
|
60
60
|
this.onPointerEvent("pointerdown", this, this.mouseDown.bind(this));
|
|
61
61
|
this.onPointerEvent("pointerup", this, this.mouseUp.bind(this));
|
|
62
62
|
this.onPointerEvent("pointercancel", this, this.mouseUp.bind(this));
|
|
63
|
-
event.
|
|
64
|
-
event.
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
}
|
|
68
|
-
});
|
|
69
|
-
event.subscribe(event.DRAGEND, function (e, draggable) {
|
|
70
|
-
if (draggable === self) {
|
|
71
|
-
self.dragEnd(e);
|
|
72
|
-
}
|
|
73
|
-
});
|
|
74
|
-
},
|
|
63
|
+
event.on(event.POINTERMOVE, this.dragMove, this);
|
|
64
|
+
event.on(event.DRAGSTART, this.dragStart, this);
|
|
65
|
+
event.on(event.DRAGEND, this.dragEnd, this);
|
|
66
|
+
}
|
|
75
67
|
|
|
76
68
|
/**
|
|
77
69
|
* Translates a pointer event to a me.event
|
|
@@ -79,12 +71,11 @@ var DraggableEntity = Entity.extend({
|
|
|
79
71
|
* @memberOf me.DraggableEntity
|
|
80
72
|
* @function
|
|
81
73
|
* @param {Object} e the pointer event you want to translate
|
|
82
|
-
* @param {String} translation the me.event you want to translate
|
|
83
|
-
* the event to
|
|
74
|
+
* @param {String} translation the me.event you want to translate the event to
|
|
84
75
|
*/
|
|
85
|
-
translatePointerEvent
|
|
86
|
-
event.
|
|
87
|
-
}
|
|
76
|
+
translatePointerEvent(e, translation) {
|
|
77
|
+
event.emit(translation, e);
|
|
78
|
+
}
|
|
88
79
|
|
|
89
80
|
/**
|
|
90
81
|
* Gets called when the user starts dragging the entity
|
|
@@ -93,14 +84,14 @@ var DraggableEntity = Entity.extend({
|
|
|
93
84
|
* @function
|
|
94
85
|
* @param {Object} x the pointer event
|
|
95
86
|
*/
|
|
96
|
-
dragStart
|
|
87
|
+
dragStart(e) {
|
|
97
88
|
if (this.dragging === false) {
|
|
98
89
|
this.dragging = true;
|
|
99
90
|
this.grabOffset.set(e.gameX, e.gameY);
|
|
100
91
|
this.grabOffset.sub(this.pos);
|
|
101
92
|
return false;
|
|
102
93
|
}
|
|
103
|
-
}
|
|
94
|
+
}
|
|
104
95
|
|
|
105
96
|
/**
|
|
106
97
|
* Gets called when the user drags this entity around
|
|
@@ -109,12 +100,12 @@ var DraggableEntity = Entity.extend({
|
|
|
109
100
|
* @function
|
|
110
101
|
* @param {Object} x the pointer event
|
|
111
102
|
*/
|
|
112
|
-
dragMove
|
|
103
|
+
dragMove(e) {
|
|
113
104
|
if (this.dragging === true) {
|
|
114
105
|
this.pos.set(e.gameX, e.gameY, this.pos.z); //TODO : z ?
|
|
115
106
|
this.pos.sub(this.grabOffset);
|
|
116
107
|
}
|
|
117
|
-
}
|
|
108
|
+
}
|
|
118
109
|
|
|
119
110
|
/**
|
|
120
111
|
* Gets called when the user stops dragging the entity
|
|
@@ -123,12 +114,12 @@ var DraggableEntity = Entity.extend({
|
|
|
123
114
|
* @function
|
|
124
115
|
* @param {Object} x the pointer event
|
|
125
116
|
*/
|
|
126
|
-
dragEnd
|
|
117
|
+
dragEnd() {
|
|
127
118
|
if (this.dragging === true) {
|
|
128
119
|
this.dragging = false;
|
|
129
120
|
return false;
|
|
130
121
|
}
|
|
131
|
-
}
|
|
122
|
+
}
|
|
132
123
|
|
|
133
124
|
/**
|
|
134
125
|
* Destructor
|
|
@@ -136,12 +127,12 @@ var DraggableEntity = Entity.extend({
|
|
|
136
127
|
* @memberOf me.DraggableEntity
|
|
137
128
|
* @function
|
|
138
129
|
*/
|
|
139
|
-
destroy
|
|
140
|
-
event.
|
|
141
|
-
event.
|
|
142
|
-
event.
|
|
130
|
+
destroy() {
|
|
131
|
+
event.off(event.POINTERMOVE, this.dragMove);
|
|
132
|
+
event.off(event.DRAGSTART, this.dragStart);
|
|
133
|
+
event.off(event.DRAGEND, this.dragEnd);
|
|
143
134
|
this.removePointerEvent("pointerdown", this);
|
|
144
135
|
this.removePointerEvent("pointerup", this);
|
|
145
136
|
}
|
|
146
|
-
}
|
|
137
|
+
};
|
|
147
138
|
export default DraggableEntity;
|
package/src/entity/droptarget.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import event from "./../system/event.js";
|
|
1
|
+
import * as event from "./../system/event.js";
|
|
2
2
|
import Entity from "./entity.js";
|
|
3
3
|
|
|
4
4
|
/**
|
|
@@ -11,7 +11,8 @@ import Entity from "./entity.js";
|
|
|
11
11
|
* @param {Number} y the y coordinates of the entity object
|
|
12
12
|
* @param {Object} settings Entity properties (see {@link me.Entity})
|
|
13
13
|
*/
|
|
14
|
-
|
|
14
|
+
|
|
15
|
+
class DroptargetEntity extends Entity {
|
|
15
16
|
/**
|
|
16
17
|
* Constructor
|
|
17
18
|
* @name init
|
|
@@ -21,7 +22,8 @@ var DroptargetEntity = Entity.extend({
|
|
|
21
22
|
* @param {Number} y the y postion of the entity
|
|
22
23
|
* @param {Object} settings the additional entity settings
|
|
23
24
|
*/
|
|
24
|
-
|
|
25
|
+
constructor(x, y, settings) {
|
|
26
|
+
super(x, y, settings);
|
|
25
27
|
/**
|
|
26
28
|
* constant for the overlaps method
|
|
27
29
|
* @public
|
|
@@ -49,10 +51,9 @@ var DroptargetEntity = Entity.extend({
|
|
|
49
51
|
* @memberOf me.DroptargetEntity
|
|
50
52
|
*/
|
|
51
53
|
this.checkMethod = null;
|
|
52
|
-
|
|
53
|
-
event.subscribe(event.DRAGEND, this.checkOnMe.bind(this));
|
|
54
|
+
event.on(event.DRAGEND, this.checkOnMe, this);
|
|
54
55
|
this.checkMethod = this[this.CHECKMETHOD_OVERLAP];
|
|
55
|
-
}
|
|
56
|
+
}
|
|
56
57
|
|
|
57
58
|
/**
|
|
58
59
|
* Sets the collision method which is going to be used to check a valid drop
|
|
@@ -61,13 +62,13 @@ var DroptargetEntity = Entity.extend({
|
|
|
61
62
|
* @function
|
|
62
63
|
* @param {Constant} checkMethod the checkmethod (defaults to CHECKMETHOD_OVERLAP)
|
|
63
64
|
*/
|
|
64
|
-
setCheckMethod
|
|
65
|
+
setCheckMethod(checkMethod) {
|
|
65
66
|
// We can improve this check,
|
|
66
67
|
// because now you can use every method in theory
|
|
67
68
|
if (typeof(this[checkMethod]) !== "undefined") {
|
|
68
69
|
this.checkMethod = this[checkMethod];
|
|
69
70
|
}
|
|
70
|
-
}
|
|
71
|
+
}
|
|
71
72
|
|
|
72
73
|
/**
|
|
73
74
|
* Checks if a dropped entity is dropped on the current entity
|
|
@@ -76,12 +77,12 @@ var DroptargetEntity = Entity.extend({
|
|
|
76
77
|
* @function
|
|
77
78
|
* @param {Object} draggableEntity the draggable entity that is dropped
|
|
78
79
|
*/
|
|
79
|
-
checkOnMe
|
|
80
|
+
checkOnMe(e, draggableEntity) {
|
|
80
81
|
if (draggableEntity && this.checkMethod(draggableEntity.getBounds())) {
|
|
81
82
|
// call the drop method on the current entity
|
|
82
83
|
this.drop(draggableEntity);
|
|
83
84
|
}
|
|
84
|
-
}
|
|
85
|
+
}
|
|
85
86
|
|
|
86
87
|
/**
|
|
87
88
|
* Gets called when a draggable entity is dropped on the current entity
|
|
@@ -90,7 +91,9 @@ var DroptargetEntity = Entity.extend({
|
|
|
90
91
|
* @function
|
|
91
92
|
* @param {Object} draggableEntity the draggable entity that is dropped
|
|
92
93
|
*/
|
|
93
|
-
drop
|
|
94
|
+
drop() {
|
|
95
|
+
|
|
96
|
+
}
|
|
94
97
|
|
|
95
98
|
/**
|
|
96
99
|
* Destructor
|
|
@@ -98,8 +101,8 @@ var DroptargetEntity = Entity.extend({
|
|
|
98
101
|
* @memberOf me.DroptargetEntity
|
|
99
102
|
* @function
|
|
100
103
|
*/
|
|
101
|
-
destroy
|
|
102
|
-
event.
|
|
104
|
+
destroy() {
|
|
105
|
+
event.off(event.DRAGEND, this.checkOnMe);
|
|
103
106
|
}
|
|
104
|
-
}
|
|
107
|
+
};
|
|
105
108
|
export default DroptargetEntity;
|