Skip to content

Instantly share code, notes, and snippets.

@lardratboy
Created August 23, 2014 03:45
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save lardratboy/8a92f03ac09a8493a0f4 to your computer and use it in GitHub Desktop.
Save lardratboy/8a92f03ac09a8493a0f4 to your computer and use it in GitHub Desktop.
(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' );
@lardratboy
Copy link
Author

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment