Skip to content

Commit 57084cb

Browse files
committed
Added Pointer.smoothFactor property, and pass new boolean to input manager.
1 parent 8fca5ab commit 57084cb

1 file changed

Lines changed: 25 additions & 6 deletions

File tree

src/input/Pointer.js

Lines changed: 25 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -120,6 +120,25 @@ var Pointer = new Class({
120120
*/
121121
this.prevPosition = new Vector2();
122122

123+
/**
124+
* The smoothing factor to apply to the Pointer position.
125+
*
126+
* Due to their nature, pointer positions are inherently noisy. While this is fine for lots of games, if you need cleaner positions
127+
* then you can set this value to apply an automatic smoothing to the positions as they are recorded.
128+
*
129+
* The default value of zero means 'no smoothing'.
130+
* Set to a small value, such as 0.2, to apply an average level of smoothing between positions.
131+
* Values above 1 will introduce excess jitter into the positions.
132+
*
133+
* Positions are only smoothed when the pointer moves. Up and Down positions are always precise.
134+
*
135+
* @name Phaser.Input.Pointer#smoothFactor
136+
* @type {number}
137+
* @default 0
138+
* @since 3.16.0
139+
*/
140+
this.smoothFactor = 0;
141+
123142
/**
124143
* The x position of this Pointer, translated into the coordinate space of the most recent Camera it interacted with.
125144
*
@@ -403,7 +422,7 @@ var Pointer = new Class({
403422
this.event = event;
404423

405424
// Sets the local x/y properties
406-
this.manager.transformPointer(this, event.pageX, event.pageY);
425+
this.manager.transformPointer(this, event.pageX, event.pageY, false);
407426

408427
// 0: Main button pressed, usually the left button or the un-initialized state
409428
if (event.button === 0)
@@ -442,7 +461,7 @@ var Pointer = new Class({
442461
this.event = event;
443462

444463
// Sets the local x/y properties
445-
this.manager.transformPointer(this, event.pageX, event.pageY);
464+
this.manager.transformPointer(this, event.pageX, event.pageY, false);
446465

447466
// 0: Main button pressed, usually the left button or the un-initialized state
448467
if (event.button === 0)
@@ -481,7 +500,7 @@ var Pointer = new Class({
481500
this.event = event;
482501

483502
// Sets the local x/y properties
484-
this.manager.transformPointer(this, event.pageX, event.pageY);
503+
this.manager.transformPointer(this, event.pageX, event.pageY, true);
485504

486505
if (this.manager.mouse.locked)
487506
{
@@ -523,7 +542,7 @@ var Pointer = new Class({
523542
this.event = event;
524543

525544
// Sets the local x/y properties
526-
this.manager.transformPointer(this, event.pageX, event.pageY);
545+
this.manager.transformPointer(this, event.pageX, event.pageY, false);
527546

528547
this.primaryDown = true;
529548
this.downX = this.x;
@@ -554,7 +573,7 @@ var Pointer = new Class({
554573
this.event = event;
555574

556575
// Sets the local x/y properties
557-
this.manager.transformPointer(this, event.pageX, event.pageY);
576+
this.manager.transformPointer(this, event.pageX, event.pageY, true);
558577

559578
this.justMoved = true;
560579

@@ -580,7 +599,7 @@ var Pointer = new Class({
580599
this.event = event;
581600

582601
// Sets the local x/y properties
583-
this.manager.transformPointer(this, event.pageX, event.pageY);
602+
this.manager.transformPointer(this, event.pageX, event.pageY, false);
584603

585604
this.primaryDown = false;
586605
this.upX = this.x;

0 commit comments

Comments
 (0)