Created
August 23, 2014 03:45
-
-
Save lardratboy/8a92f03ac09a8493a0f4 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(function(property) { | |
var local = new Phaser.Point(); | |
function askAncestors( child, pointer ) { | |
for ( var parent = child.parent; parent; parent = parent.parent ) { | |
var clip = parent[property]; | |
if ( !clip ) continue; | |
parent.game.input.getLocalPosition( parent, pointer, local); | |
var cx = local.x - clip.x, cy = local.y - clip.y; | |
return (0 <= cx) && (cx < clip.width) && (0 <= cy) && (cy < clip.height); | |
} | |
return true; | |
} | |
var _checkPointerDown_ = Phaser.InputHandler.prototype.checkPointerDown; | |
Phaser.InputHandler.prototype.checkPointerDown = function(pointer, fastTest) { | |
if ( !_checkPointerDown_.call( this, pointer, fastTest ) ) return false; | |
return askAncestors( this.sprite, pointer ); | |
} | |
var _checkPointerOver_ = Phaser.InputHandler.prototype.checkPointerOver; | |
Phaser.InputHandler.prototype.checkPointerOver = function(pointer, fastTest) { | |
if ( !_checkPointerOver_.call( this, pointer, fastTest ) ) return false; | |
return askAncestors( this.sprite, pointer ); | |
} | |
})( 'input_clipping_rect' ); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Phaser.InputHandler extension to perform child input clipping, a bubbling event system would be better but this is a quick way to provide a way for ancestors to reject input for a child.