forked from phaserjs/phaser
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathPointer.js
More file actions
1280 lines (1126 loc) · 37.4 KB
/
Copy pathPointer.js
File metadata and controls
1280 lines (1126 loc) · 37.4 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
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
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
/**
* @author Richard Davey <rich@photonstorm.com>
* @copyright 2020 Photon Storm Ltd.
* @license {@link https://opensource.org/licenses/MIT|MIT License}
*/
var Angle = require('../math/angle/Between');
var Class = require('../utils/Class');
var Distance = require('../math/distance/DistanceBetween');
var FuzzyEqual = require('../math/fuzzy/Equal');
var SmoothStepInterpolation = require('../math/interpolation/SmoothStepInterpolation');
var Vector2 = require('../math/Vector2');
var OS = require('../device/OS');
/**
* @classdesc
* A Pointer object encapsulates both mouse and touch input within Phaser.
*
* By default, Phaser will create 2 pointers for your game to use. If you require more, i.e. for a multi-touch
* game, then use the `InputPlugin.addPointer` method to do so, rather than instantiating this class directly,
* otherwise it won't be managed by the input system.
*
* You can reference the current active pointer via `InputPlugin.activePointer`. You can also use the properties
* `InputPlugin.pointer1` through to `pointer10`, for each pointer you have enabled in your game.
*
* The properties of this object are set by the Input Plugin during processing. This object is then sent in all
* input related events that the Input Plugin emits, so you can reference properties from it directly in your
* callbacks.
*
* @class Pointer
* @memberof Phaser.Input
* @constructor
* @since 3.0.0
*
* @param {Phaser.Input.InputManager} manager - A reference to the Input Manager.
* @param {number} id - The internal ID of this Pointer.
*/
var Pointer = new Class({
initialize:
function Pointer (manager, id)
{
/**
* A reference to the Input Manager.
*
* @name Phaser.Input.Pointer#manager
* @type {Phaser.Input.InputManager}
* @since 3.0.0
*/
this.manager = manager;
/**
* The internal ID of this Pointer.
*
* @name Phaser.Input.Pointer#id
* @type {number}
* @readonly
* @since 3.0.0
*/
this.id = id;
/**
* The most recent native DOM Event this Pointer has processed.
*
* @name Phaser.Input.Pointer#event
* @type {(TouchEvent|MouseEvent)}
* @since 3.0.0
*/
this.event;
/**
* The DOM element the Pointer was pressed down on, taken from the DOM event.
* In a default set-up this will be the Canvas that Phaser is rendering to, or the Window element.
*
* @name Phaser.Input.Pointer#downElement
* @type {any}
* @readonly
* @since 3.16.0
*/
this.downElement;
/**
* The DOM element the Pointer was released on, taken from the DOM event.
* In a default set-up this will be the Canvas that Phaser is rendering to, or the Window element.
*
* @name Phaser.Input.Pointer#upElement
* @type {any}
* @readonly
* @since 3.16.0
*/
this.upElement;
/**
* The camera the Pointer interacted with during its last update.
*
* A Pointer can only ever interact with one camera at once, which will be the top-most camera
* in the list should multiple cameras be positioned on-top of each other.
*
* @name Phaser.Input.Pointer#camera
* @type {Phaser.Cameras.Scene2D.Camera}
* @default null
* @since 3.0.0
*/
this.camera = null;
/**
* A read-only property that indicates which button was pressed, or released, on the pointer
* during the most recent event. It is only set during `up` and `down` events.
*
* On Touch devices the value is always 0.
*
* Users may change the configuration of buttons on their pointing device so that if an event's button property
* is zero, it may not have been caused by the button that is physically left–most on the pointing device;
* however, it should behave as if the left button was clicked in the standard button layout.
*
* @name Phaser.Input.Pointer#button
* @type {number}
* @readonly
* @default 0
* @since 3.18.0
*/
this.button = 0;
/**
* 0: No button or un-initialized
* 1: Left button
* 2: Right button
* 4: Wheel button or middle button
* 8: 4th button (typically the "Browser Back" button)
* 16: 5th button (typically the "Browser Forward" button)
*
* For a mouse configured for left-handed use, the button actions are reversed.
* In this case, the values are read from right to left.
*
* @name Phaser.Input.Pointer#buttons
* @type {number}
* @default 0
* @since 3.0.0
*/
this.buttons = 0;
/**
* The position of the Pointer in screen space.
*
* @name Phaser.Input.Pointer#position
* @type {Phaser.Math.Vector2}
* @readonly
* @since 3.0.0
*/
this.position = new Vector2();
/**
* The previous position of the Pointer in screen space.
*
* The old x and y values are stored in here during the InputManager.transformPointer call.
*
* Use the properties `velocity`, `angle` and `distance` to create your own gesture recognition.
*
* @name Phaser.Input.Pointer#prevPosition
* @type {Phaser.Math.Vector2}
* @readonly
* @since 3.11.0
*/
this.prevPosition = new Vector2();
/**
* An internal vector used for calculations of the pointer speed and angle.
*
* @name Phaser.Input.Pointer#midPoint
* @type {Phaser.Math.Vector2}
* @private
* @since 3.16.0
*/
this.midPoint = new Vector2(-1, -1);
/**
* The current velocity of the Pointer, based on its current and previous positions.
*
* This value is smoothed out each frame, according to the `motionFactor` property.
*
* This property is updated whenever the Pointer moves, regardless of any button states. In other words,
* it changes based on movement alone - a button doesn't have to be pressed first.
*
* @name Phaser.Input.Pointer#velocity
* @type {Phaser.Math.Vector2}
* @readonly
* @since 3.16.0
*/
this.velocity = new Vector2();
/**
* The current angle the Pointer is moving, in radians, based on its previous and current position.
*
* The angle is based on the old position facing to the current position.
*
* This property is updated whenever the Pointer moves, regardless of any button states. In other words,
* it changes based on movement alone - a button doesn't have to be pressed first.
*
* @name Phaser.Input.Pointer#angle
* @type {number}
* @readonly
* @since 3.16.0
*/
this.angle = 0;
/**
* The distance the Pointer has moved, based on its previous and current position.
*
* This value is smoothed out each frame, according to the `motionFactor` property.
*
* This property is updated whenever the Pointer moves, regardless of any button states. In other words,
* it changes based on movement alone - a button doesn't have to be pressed first.
*
* If you need the total distance travelled since the primary buttons was pressed down,
* then use the `Pointer.getDistance` method.
*
* @name Phaser.Input.Pointer#distance
* @type {number}
* @readonly
* @since 3.16.0
*/
this.distance = 0;
/**
* The smoothing factor to apply to the Pointer position.
*
* Due to their nature, pointer positions are inherently noisy. While this is fine for lots of games, if you need cleaner positions
* then you can set this value to apply an automatic smoothing to the positions as they are recorded.
*
* The default value of zero means 'no smoothing'.
* Set to a small value, such as 0.2, to apply an average level of smoothing between positions. You can do this by changing this
* value directly, or by setting the `input.smoothFactor` property in the Game Config.
*
* Positions are only smoothed when the pointer moves. If the primary button on this Pointer enters an Up or Down state, then the position
* is always precise, and not smoothed.
*
* @name Phaser.Input.Pointer#smoothFactor
* @type {number}
* @default 0
* @since 3.16.0
*/
this.smoothFactor = 0;
/**
* The factor applied to the motion smoothing each frame.
*
* This value is passed to the Smooth Step Interpolation that is used to calculate the velocity,
* angle and distance of the Pointer. It's applied every frame, until the midPoint reaches the current
* position of the Pointer. 0.2 provides a good average but can be increased if you need a
* quicker update and are working in a high performance environment. Never set this value to
* zero.
*
* @name Phaser.Input.Pointer#motionFactor
* @type {number}
* @default 0.2
* @since 3.16.0
*/
this.motionFactor = 0.2;
/**
* The x position of this Pointer, translated into the coordinate space of the most recent Camera it interacted with.
*
* If you wish to use this value _outside_ of an input event handler then you should update it first by calling
* the `Pointer.updateWorldPoint` method.
*
* @name Phaser.Input.Pointer#worldX
* @type {number}
* @default 0
* @since 3.10.0
*/
this.worldX = 0;
/**
* The y position of this Pointer, translated into the coordinate space of the most recent Camera it interacted with.
*
* If you wish to use this value _outside_ of an input event handler then you should update it first by calling
* the `Pointer.updateWorldPoint` method.
*
* @name Phaser.Input.Pointer#worldY
* @type {number}
* @default 0
* @since 3.10.0
*/
this.worldY = 0;
/**
* Time when this Pointer was most recently moved (regardless of the state of its buttons, if any)
*
* @name Phaser.Input.Pointer#moveTime
* @type {number}
* @default 0
* @since 3.0.0
*/
this.moveTime = 0;
/**
* X coordinate of the Pointer when Button 1 (left button), or Touch, was pressed, used for dragging objects.
*
* @name Phaser.Input.Pointer#downX
* @type {number}
* @default 0
* @since 3.0.0
*/
this.downX = 0;
/**
* Y coordinate of the Pointer when Button 1 (left button), or Touch, was pressed, used for dragging objects.
*
* @name Phaser.Input.Pointer#downY
* @type {number}
* @default 0
* @since 3.0.0
*/
this.downY = 0;
/**
* The Event timestamp when the first button, or Touch input, was pressed. Used for dragging objects.
*
* @name Phaser.Input.Pointer#downTime
* @type {number}
* @default 0
* @since 3.0.0
*/
this.downTime = 0;
/**
* X coordinate of the Pointer when Button 1 (left button), or Touch, was released, used for dragging objects.
*
* @name Phaser.Input.Pointer#upX
* @type {number}
* @default 0
* @since 3.0.0
*/
this.upX = 0;
/**
* Y coordinate of the Pointer when Button 1 (left button), or Touch, was released, used for dragging objects.
*
* @name Phaser.Input.Pointer#upY
* @type {number}
* @default 0
* @since 3.0.0
*/
this.upY = 0;
/**
* The Event timestamp when the final button, or Touch input, was released. Used for dragging objects.
*
* @name Phaser.Input.Pointer#upTime
* @type {number}
* @default 0
* @since 3.0.0
*/
this.upTime = 0;
/**
* Is the primary button down? (usually button 0, the left mouse button)
*
* @name Phaser.Input.Pointer#primaryDown
* @type {boolean}
* @default false
* @since 3.0.0
*/
this.primaryDown = false;
/**
* Is _any_ button on this pointer considered as being down?
*
* @name Phaser.Input.Pointer#isDown
* @type {boolean}
* @default false
* @since 3.0.0
*/
this.isDown = false;
/**
* Did the previous input event come from a Touch input (true) or Mouse? (false)
*
* @name Phaser.Input.Pointer#wasTouch
* @type {boolean}
* @default false
* @since 3.0.0
*/
this.wasTouch = false;
/**
* Did this Pointer get canceled by a touchcancel event?
*
* Note: "canceled" is the American-English spelling of "cancelled". Please don't submit PRs correcting it!
*
* @name Phaser.Input.Pointer#wasCanceled
* @type {boolean}
* @default false
* @since 3.15.0
*/
this.wasCanceled = false;
/**
* If the mouse is locked, the horizontal relative movement of the Pointer in pixels since last frame.
*
* @name Phaser.Input.Pointer#movementX
* @type {number}
* @default 0
* @since 3.0.0
*/
this.movementX = 0;
/**
* If the mouse is locked, the vertical relative movement of the Pointer in pixels since last frame.
*
* @name Phaser.Input.Pointer#movementY
* @type {number}
* @default 0
* @since 3.0.0
*/
this.movementY = 0;
/**
* The identifier property of the Pointer as set by the DOM event when this Pointer is started.
*
* @name Phaser.Input.Pointer#identifier
* @type {number}
* @since 3.10.0
*/
this.identifier = 0;
/**
* The pointerId property of the Pointer as set by the DOM event when this Pointer is started.
* The browser can and will recycle this value.
*
* @name Phaser.Input.Pointer#pointerId
* @type {number}
* @since 3.10.0
*/
this.pointerId = null;
/**
* An active Pointer is one that is currently pressed down on the display.
* A Mouse is always considered as active.
*
* @name Phaser.Input.Pointer#active
* @type {boolean}
* @since 3.10.0
*/
this.active = (id === 0) ? true : false;
/**
* Is this pointer Pointer Locked?
*
* Only a mouse pointer can be locked and it only becomes locked when requested via
* the browsers Pointer Lock API.
*
* You can request this by calling the `this.input.mouse.requestPointerLock()` method from
* a `pointerdown` or `pointerup` event handler.
*
* @name Phaser.Input.Pointer#locked
* @readonly
* @type {boolean}
* @since 3.19.0
*/
this.locked = false;
/**
* The horizontal scroll amount that occurred due to the user moving a mouse wheel or similar input device.
*
* @name Phaser.Input.Pointer#deltaX
* @type {number}
* @default 0
* @since 3.18.0
*/
this.deltaX = 0;
/**
* The vertical scroll amount that occurred due to the user moving a mouse wheel or similar input device.
* This value will typically be less than 0 if the user scrolls up and greater than zero if scrolling down.
*
* @name Phaser.Input.Pointer#deltaY
* @type {number}
* @default 0
* @since 3.18.0
*/
this.deltaY = 0;
/**
* The z-axis scroll amount that occurred due to the user moving a mouse wheel or similar input device.
*
* @name Phaser.Input.Pointer#deltaZ
* @type {number}
* @default 0
* @since 3.18.0
*/
this.deltaZ = 0;
},
/**
* Takes a Camera and updates this Pointer's `worldX` and `worldY` values so they are
* the result of a translation through the given Camera.
*
* Note that the values will be automatically replaced the moment the Pointer is
* updated by an input event, such as a mouse move, so should be used immediately.
*
* @method Phaser.Input.Pointer#updateWorldPoint
* @since 3.19.0
*
* @param {Phaser.Cameras.Scene2D.Camera} camera - The Camera which is being tested against.
*
* @return {this} This Pointer object.
*/
updateWorldPoint: function (camera)
{
// Stores the world point inside of tempPoint
var temp = camera.getWorldPoint(this.x, this.y);
this.worldX = temp.x;
this.worldY = temp.y;
return this;
},
/**
* Takes a Camera and returns a Vector2 containing the translated position of this Pointer
* within that Camera. This can be used to convert this Pointers position into camera space.
*
* @method Phaser.Input.Pointer#positionToCamera
* @since 3.0.0
*
* @param {Phaser.Cameras.Scene2D.Camera} camera - The Camera to use for the translation.
* @param {(Phaser.Math.Vector2|object)} [output] - A Vector2-like object in which to store the translated position.
*
* @return {(Phaser.Math.Vector2|object)} A Vector2 containing the translated coordinates of this Pointer, based on the given camera.
*/
positionToCamera: function (camera, output)
{
return camera.getWorldPoint(this.x, this.y, output);
},
/**
* Calculates the motion of this Pointer, including its velocity and angle of movement.
* This method is called automatically each frame by the Input Manager.
*
* @method Phaser.Input.Pointer#updateMotion
* @private
* @since 3.16.0
*/
updateMotion: function ()
{
var cx = this.position.x;
var cy = this.position.y;
var mx = this.midPoint.x;
var my = this.midPoint.y;
if (cx === mx && cy === my)
{
// Nothing to do here
return;
}
// Moving towards our goal ...
var vx = SmoothStepInterpolation(this.motionFactor, mx, cx);
var vy = SmoothStepInterpolation(this.motionFactor, my, cy);
if (FuzzyEqual(vx, cx, 0.1))
{
vx = cx;
}
if (FuzzyEqual(vy, cy, 0.1))
{
vy = cy;
}
this.midPoint.set(vx, vy);
var dx = cx - vx;
var dy = cy - vy;
this.velocity.set(dx, dy);
this.angle = Angle(vx, vy, cx, cy);
this.distance = Math.sqrt(dx * dx + dy * dy);
},
/**
* Internal method to handle a Mouse Up Event.
*
* @method Phaser.Input.Pointer#up
* @private
* @since 3.0.0
*
* @param {MouseEvent} event - The Mouse Event to process.
*/
up: function (event)
{
if ('buttons' in event)
{
this.buttons = event.buttons;
}
this.event = event;
this.button = event.button;
this.upElement = event.target;
// Sets the local x/y properties
this.manager.transformPointer(this, event.pageX, event.pageY, false);
// 0: Main button pressed, usually the left button or the un-initialized state
if (event.button === 0)
{
this.primaryDown = false;
this.upX = this.x;
this.upY = this.y;
}
if (this.buttons === 0)
{
// No more buttons are still down
this.isDown = false;
this.upTime = event.timeStamp;
this.wasTouch = false;
}
},
/**
* Internal method to handle a Mouse Down Event.
*
* @method Phaser.Input.Pointer#down
* @private
* @since 3.0.0
*
* @param {MouseEvent} event - The Mouse Event to process.
*/
down: function (event)
{
if ('buttons' in event)
{
this.buttons = event.buttons;
}
this.event = event;
this.button = event.button;
this.downElement = event.target;
// Sets the local x/y properties
this.manager.transformPointer(this, event.pageX, event.pageY, false);
// 0: Main button pressed, usually the left button or the un-initialized state
if (event.button === 0)
{
this.primaryDown = true;
this.downX = this.x;
this.downY = this.y;
}
if (OS.macOS && event.ctrlKey)
{
// Override button settings on macOS
this.buttons = 2;
this.primaryDown = false;
}
if (!this.isDown)
{
this.isDown = true;
this.downTime = event.timeStamp;
}
this.wasTouch = false;
},
/**
* Internal method to handle a Mouse Move Event.
*
* @method Phaser.Input.Pointer#move
* @private
* @since 3.0.0
*
* @param {MouseEvent} event - The Mouse Event to process.
*/
move: function (event)
{
if ('buttons' in event)
{
this.buttons = event.buttons;
}
this.event = event;
// Sets the local x/y properties
this.manager.transformPointer(this, event.pageX, event.pageY, true);
if (this.locked)
{
// Multiple DOM events may occur within one frame, but only one Phaser event will fire
this.movementX = event.movementX || event.mozMovementX || event.webkitMovementX || 0;
this.movementY = event.movementY || event.mozMovementY || event.webkitMovementY || 0;
}
this.moveTime = event.timeStamp;
this.wasTouch = false;
},
/**
* Internal method to handle a Mouse Wheel Event.
*
* @method Phaser.Input.Pointer#wheel
* @private
* @since 3.18.0
*
* @param {WheelEvent} event - The Wheel Event to process.
*/
wheel: function (event)
{
if ('buttons' in event)
{
this.buttons = event.buttons;
}
this.event = event;
// Sets the local x/y properties
this.manager.transformPointer(this, event.pageX, event.pageY, false);
this.deltaX = event.deltaX;
this.deltaY = event.deltaY;
this.deltaZ = event.deltaZ;
this.wasTouch = false;
},
/**
* Internal method to handle a Touch Start Event.
*
* @method Phaser.Input.Pointer#touchstart
* @private
* @since 3.0.0
*
* @param {Touch} touch - The Changed Touch from the Touch Event.
* @param {TouchEvent} event - The full Touch Event.
*/
touchstart: function (touch, event)
{
if (touch['pointerId'])
{
this.pointerId = touch.pointerId;
}
this.identifier = touch.identifier;
this.target = touch.target;
this.active = true;
this.buttons = 1;
this.event = event;
this.downElement = touch.target;
// Sets the local x/y properties
this.manager.transformPointer(this, touch.pageX, touch.pageY, false);
this.primaryDown = true;
this.downX = this.x;
this.downY = this.y;
this.downTime = event.timeStamp;
this.isDown = true;
this.wasTouch = true;
this.wasCanceled = false;
this.updateMotion();
},
/**
* Internal method to handle a Touch Move Event.
*
* @method Phaser.Input.Pointer#touchmove
* @private
* @since 3.0.0
*
* @param {Touch} touch - The Changed Touch from the Touch Event.
* @param {TouchEvent} event - The full Touch Event.
*/
touchmove: function (touch, event)
{
this.event = event;
// Sets the local x/y properties
this.manager.transformPointer(this, touch.pageX, touch.pageY, true);
this.moveTime = event.timeStamp;
this.wasTouch = true;
this.updateMotion();
},
/**
* Internal method to handle a Touch End Event.
*
* @method Phaser.Input.Pointer#touchend
* @private
* @since 3.0.0
*
* @param {Touch} touch - The Changed Touch from the Touch Event.
* @param {TouchEvent} event - The full Touch Event.
*/
touchend: function (touch, event)
{
this.buttons = 0;
this.event = event;
this.upElement = touch.target;
// Sets the local x/y properties
this.manager.transformPointer(this, touch.pageX, touch.pageY, false);
this.primaryDown = false;
this.upX = this.x;
this.upY = this.y;
this.upTime = event.timeStamp;
this.isDown = false;
this.wasTouch = true;
this.wasCanceled = false;
this.active = false;
this.updateMotion();
},
/**
* Internal method to handle a Touch Cancel Event.
*
* @method Phaser.Input.Pointer#touchcancel
* @private
* @since 3.15.0
*
* @param {Touch} touch - The Changed Touch from the Touch Event.
* @param {TouchEvent} event - The full Touch Event.
*/
touchcancel: function (touch, event)
{
this.buttons = 0;
this.event = event;
this.upElement = touch.target;
// Sets the local x/y properties
this.manager.transformPointer(this, touch.pageX, touch.pageY, false);
this.primaryDown = false;
this.upX = this.x;
this.upY = this.y;
this.upTime = event.timeStamp;
this.isDown = false;
this.wasTouch = true;
this.wasCanceled = true;
this.active = false;
},
/**
* Checks to see if any buttons are being held down on this Pointer.
*
* @method Phaser.Input.Pointer#noButtonDown
* @since 3.0.0
*
* @return {boolean} `true` if no buttons are being held down.
*/
noButtonDown: function ()
{
return (this.buttons === 0);
},
/**
* Checks to see if the left button is being held down on this Pointer.
*
* @method Phaser.Input.Pointer#leftButtonDown
* @since 3.0.0
*
* @return {boolean} `true` if the left button is being held down.
*/
leftButtonDown: function ()
{
return (this.buttons & 1) ? true : false;
},
/**
* Checks to see if the right button is being held down on this Pointer.
*
* @method Phaser.Input.Pointer#rightButtonDown
* @since 3.0.0
*
* @return {boolean} `true` if the right button is being held down.
*/
rightButtonDown: function ()
{
return (this.buttons & 2) ? true : false;
},
/**
* Checks to see if the middle button is being held down on this Pointer.
*
* @method Phaser.Input.Pointer#middleButtonDown
* @since 3.0.0
*
* @return {boolean} `true` if the middle button is being held down.
*/
middleButtonDown: function ()
{
return (this.buttons & 4) ? true : false;
},
/**
* Checks to see if the back button is being held down on this Pointer.
*
* @method Phaser.Input.Pointer#backButtonDown
* @since 3.0.0
*
* @return {boolean} `true` if the back button is being held down.
*/
backButtonDown: function ()
{
return (this.buttons & 8) ? true : false;
},
/**
* Checks to see if the forward button is being held down on this Pointer.
*
* @method Phaser.Input.Pointer#forwardButtonDown
* @since 3.0.0
*
* @return {boolean} `true` if the forward button is being held down.
*/
forwardButtonDown: function ()
{
return (this.buttons & 16) ? true : false;
},
/**
* Checks to see if the left button was just released on this Pointer.
*
* @method Phaser.Input.Pointer#leftButtonReleased
* @since 3.18.0
*
* @return {boolean} `true` if the left button was just released.
*/
leftButtonReleased: function ()
{
return (this.button === 0 && !this.isDown);
},
/**
* Checks to see if the right button was just released on this Pointer.
*
* @method Phaser.Input.Pointer#rightButtonReleased
* @since 3.18.0
*
* @return {boolean} `true` if the right button was just released.
*/
rightButtonReleased: function ()
{
return (this.button === 2 && !this.isDown);
},
/**
* Checks to see if the middle button was just released on this Pointer.
*
* @method Phaser.Input.Pointer#middleButtonReleased
* @since 3.18.0
*
* @return {boolean} `true` if the middle button was just released.
*/
middleButtonReleased: function ()
{
return (this.button === 1 && !this.isDown);
},
/**
* Checks to see if the back button was just released on this Pointer.
*
* @method Phaser.Input.Pointer#backButtonReleased
* @since 3.18.0
*