@@ -356,6 +356,16 @@ var InputPlugin = new Class({
356356 */
357357 this . _validTypes = [ 'onDown' , 'onUp' , 'onOver' , 'onOut' , 'onMove' , 'onDragStart' , 'onDrag' , 'onDragEnd' , 'onDragEnter' , 'onDragLeave' , 'onDragOver' , 'onDrop' ] ;
358358
359+ /**
360+ * Internal property that tracks frame event state.
361+ *
362+ * @name Phaser.Input.InputPlugin#_updatedThisFrame
363+ * @type {boolean }
364+ * @private
365+ * @since 3.18.0
366+ */
367+ this . _updatedThisFrame = false ;
368+
359369 scene . sys . events . once ( SceneEvents . BOOT , this . boot , this ) ;
360370 scene . sys . events . on ( SceneEvents . START , this . start , this ) ;
361371 } ,
@@ -525,10 +535,9 @@ var InputPlugin = new Class({
525535 {
526536 this . pluginEvents . emit ( Events . UPDATE , time , delta ) ;
527537
528- /*
529- if (this.pollRate > -1)
538+ if ( this . pollRate > - 1 && ! this . _updatedThisFrame )
530539 {
531- this.update (time, delta);
540+ this . updatePoll ( time , delta ) ;
532541 }
533542 else
534543 {
@@ -539,7 +548,92 @@ var InputPlugin = new Class({
539548
540549 this . pluginEvents . emit ( Events . UPDATE , time , delta ) ;
541550 }
542- */
551+
552+ this . _updatedThisFrame = false ;
553+ } ,
554+
555+ updatePoll : function ( time , delta )
556+ {
557+ console . log ( 'poll' ) ;
558+
559+ if ( ! this . isActive ( ) )
560+ {
561+ return false ;
562+ }
563+
564+ if ( this . pollRate > 0 )
565+ {
566+ this . _pollTimer -= delta ;
567+
568+ if ( this . _pollTimer < 0 )
569+ {
570+ // Discard timer diff, we're ready to poll again
571+ this . _pollTimer = this . pollRate ;
572+ }
573+ else
574+ {
575+ // Not enough time has elapsed since the last poll, so abort now
576+ return ;
577+ }
578+ }
579+
580+ // We got this far? Then we should poll for movement
581+ var manager = this . manager ;
582+ var pointers = manager . pointers ;
583+ var pointersTotal = manager . pointersTotal ;
584+ var captured = false ;
585+
586+ for ( var i = 0 ; i < pointersTotal ; i ++ )
587+ {
588+ var pointer = pointers [ i ] ;
589+
590+ // Always reset this array
591+ this . _tempZones = [ ] ;
592+
593+ // _temp contains a hit tested and camera culled list of IO objects
594+ this . _temp = this . hitTestPointer ( pointer ) ;
595+
596+ this . sortGameObjects ( this . _temp ) ;
597+ this . sortGameObjects ( this . _tempZones ) ;
598+
599+ if ( this . topOnly )
600+ {
601+ // Only the top-most one counts now, so safely ignore the rest
602+ if ( this . _temp . length )
603+ {
604+ this . _temp . splice ( 1 ) ;
605+ }
606+
607+ if ( this . _tempZones . length )
608+ {
609+ this . _tempZones . splice ( 1 ) ;
610+ }
611+ }
612+
613+ var total = 0 ;
614+
615+ // TODO: Enable for touch - the method needs recoding to take ALL pointers at once
616+ // and process them all together, in the same batch, otherwise the justOut and stillOver
617+ // arrays will get corrupted in multi-touch enabled games. For now, we'll enable it for
618+ // single touch games (which is probably the majority anyway).
619+ if ( pointersTotal < 3 || ! pointer . wasTouch )
620+ {
621+ total += this . processOverOutEvents ( pointer ) ;
622+ }
623+
624+ if ( pointer . justMoved )
625+ {
626+ total += this . processMoveEvents ( pointer ) ;
627+ }
628+
629+ if ( total > 0 && manager . globalTopOnly )
630+ {
631+ // We interacted with an event in this Scene, so block any Scenes below us from doing the same this frame
632+ captured = true ;
633+ }
634+ }
635+
636+ return captured ;
543637 } ,
544638
545639 /**
@@ -553,37 +647,21 @@ var InputPlugin = new Class({
553647 *
554648 * @param {number } time - The time value from the most recent Game step. Typically a high-resolution timer value, or Date.now().
555649 * @param {number } delta - The delta value since the last frame. This is smoothed to avoid delta spikes by the TimeStep class.
650+ *
651+ * @return {boolean } `true` if this Scene has captured the input events from all other Scenes, otherwise `false`.
556652 */
557653 update : function ( time , delta )
558654 {
559655 if ( ! this . isActive ( ) )
560656 {
561- return ;
657+ return false ;
562658 }
563659
564660 var manager = this . manager ;
565661
566- // this.pluginEvents.emit(Events.UPDATE, time, delta);
567-
568- // Another Scene above this one has already consumed the input events, or we're in transition
569- if ( manager . globalTopOnly && manager . ignoreEvents )
570- {
571- return ;
572- }
573-
574- if ( this . pollRate > 0 )
575- {
576- this . _pollTimer -= delta ;
577-
578- if ( this . _pollTimer < 0 )
579- {
580- // Discard timer diff
581- this . _pollTimer = this . pollRate ;
582- }
583- }
584-
585- var pointers = this . manager . pointers ;
586- var pointersTotal = this . manager . pointersTotal ;
662+ var pointers = manager . pointers ;
663+ var pointersTotal = manager . pointersTotal ;
664+ var captured = false ;
587665
588666 for ( var i = 0 ; i < pointersTotal ; i ++ )
589667 {
@@ -641,9 +719,13 @@ var InputPlugin = new Class({
641719 if ( total > 0 && manager . globalTopOnly )
642720 {
643721 // We interacted with an event in this Scene, so block any Scenes below us from doing the same this frame
644- manager . ignoreEvents = true ;
722+ captured = true ;
645723 }
646724 }
725+
726+ this . _updatedThisFrame = true ;
727+
728+ return captured ;
647729 } ,
648730
649731 /**
0 commit comments