|
4 | 4 | * @license {@link https://github.com/photonstorm/phaser/blob/master/license.txt|MIT License} |
5 | 5 | */ |
6 | 6 |
|
| 7 | +var Angle = require('../math/angle/Between'); |
7 | 8 | var Class = require('../utils/Class'); |
8 | 9 | var Distance = require('../math/distance/DistanceBetween'); |
9 | 10 | var FuzzyEqual = require('../math/fuzzy/Equal'); |
@@ -449,7 +450,14 @@ var Pointer = new Class({ |
449 | 450 | */ |
450 | 451 | this.active = (id === 0) ? true : false; |
451 | 452 |
|
452 | | - this.history = []; |
| 453 | + /** |
| 454 | + * Time when this Pointer was most recently updated by the Game step. |
| 455 | + * |
| 456 | + * @name Phaser.Input.Pointer#time |
| 457 | + * @type {number} |
| 458 | + * @since 3.16.0 |
| 459 | + */ |
| 460 | + this.time = 0; |
453 | 461 | }, |
454 | 462 |
|
455 | 463 | /** |
@@ -477,14 +485,16 @@ var Pointer = new Class({ |
477 | 485 | * @private |
478 | 486 | * @since 3.0.0 |
479 | 487 | */ |
480 | | - reset: function () |
| 488 | + reset: function (time) |
481 | 489 | { |
482 | 490 | this.dirty = false; |
483 | 491 |
|
484 | 492 | this.justDown = false; |
485 | 493 | this.justUp = false; |
486 | 494 | this.justMoved = false; |
487 | 495 |
|
| 496 | + this.time = time; |
| 497 | + |
488 | 498 | this.movementX = 0; |
489 | 499 | this.movementY = 0; |
490 | 500 | }, |
@@ -863,17 +873,81 @@ var Pointer = new Class({ |
863 | 873 | }, |
864 | 874 |
|
865 | 875 | /** |
866 | | - * Returns the distance between the Pointer's current position and where it was |
867 | | - * first pressed down (the `downX` and `downY` properties) |
| 876 | + * If the Pointer has a button pressed down at the time this method is called, it will return the |
| 877 | + * distance between the Pointer's `downX` and `downY` values and the current position. |
| 878 | + * |
| 879 | + * If no button is held down, it will return the last recorded distance, based on where |
| 880 | + * the Pointer was when the button was released. |
| 881 | + * |
| 882 | + * If you wish to get the distance being travelled currently, based on the velocity of the Pointer, |
| 883 | + * then see the `Pointer.distance` property. |
868 | 884 | * |
869 | 885 | * @method Phaser.Input.Pointer#getDistance |
870 | 886 | * @since 3.13.0 |
871 | 887 | * |
872 | | - * @return {number} The distance the Pointer has moved since being pressed down. |
| 888 | + * @return {number} The distance the Pointer moved. |
873 | 889 | */ |
874 | 890 | getDistance: function () |
875 | 891 | { |
876 | | - return Distance(this.downX, this.downY, this.x, this.y); |
| 892 | + if (this.isDown) |
| 893 | + { |
| 894 | + return Distance(this.downX, this.downY, this.x, this.y); |
| 895 | + } |
| 896 | + else |
| 897 | + { |
| 898 | + return Distance(this.downX, this.downY, this.upX, this.upY); |
| 899 | + } |
| 900 | + }, |
| 901 | + |
| 902 | + /** |
| 903 | + * If the Pointer has a button pressed down at the time this method is called, it will return the |
| 904 | + * duration since the Pointer's was pressed down. |
| 905 | + * |
| 906 | + * If no button is held down, it will return the last recorded duration, based on the time |
| 907 | + * the Pointer button was released. |
| 908 | + * |
| 909 | + * @method Phaser.Input.Pointer#getDuration |
| 910 | + * @since 3.16.0 |
| 911 | + * |
| 912 | + * @return {number} The duration the Pointer was held down for in milliseconds. |
| 913 | + */ |
| 914 | + getDuration: function () |
| 915 | + { |
| 916 | + if (this.isDown) |
| 917 | + { |
| 918 | + return (this.time - this.downTime); |
| 919 | + } |
| 920 | + else |
| 921 | + { |
| 922 | + return (this.upTime - this.downTime); |
| 923 | + } |
| 924 | + }, |
| 925 | + |
| 926 | + /** |
| 927 | + * If the Pointer has a button pressed down at the time this method is called, it will return the |
| 928 | + * angle between the Pointer's `downX` and `downY` values and the current position. |
| 929 | + * |
| 930 | + * If no button is held down, it will return the last recorded angle, based on where |
| 931 | + * the Pointer was when the button was released. |
| 932 | + * |
| 933 | + * If you wish to get the current angle, based on the velocity of the Pointer, then |
| 934 | + * see the `Pointer.angle` property. |
| 935 | + * |
| 936 | + * @method Phaser.Input.Pointer#getAngle |
| 937 | + * @since 3.16.0 |
| 938 | + * |
| 939 | + * @return {number} The angle between the Pointer's 'up' and 'down' coordinates. |
| 940 | + */ |
| 941 | + getAngle: function () |
| 942 | + { |
| 943 | + if (this.isDown) |
| 944 | + { |
| 945 | + return Angle(this.x, this.y, this.downX, this.downY); |
| 946 | + } |
| 947 | + else |
| 948 | + { |
| 949 | + return Angle(this.upX, this.upY, this.downX, this.downY); |
| 950 | + } |
877 | 951 | }, |
878 | 952 |
|
879 | 953 | /** |
|
0 commit comments