Skip to content

Instantly share code, notes, and snippets.

@lardratboy
Last active August 29, 2015 14:05
Show Gist options
  • Save lardratboy/357afa1a76c99663dd25 to your computer and use it in GitHub Desktop.
Save lardratboy/357afa1a76c99663dd25 to your computer and use it in GitHub Desktop.
setcapture_phaser_input.js
(function(property) {
Phaser.Input.prototype.getCapture = function() {
return this[property] && this[property].captor;
}
Phaser.Input.prototype.setCapture = function( inputHandlers ) {
this[property] = this[property] || {captor:undefined,inputStack:[]};
if ( 0 !== this[property].inputStack.length ) {this.releaseCapture();}
this[property].inputStack.push( this.interactiveItems );
if ( !(inputHandlers instanceof Object) ) { inputHandlers = [ inputHandlers ]; }
this[property].captor = inputHandlers;
this.interactiveItems = new Phaser.ArrayList();
for ( var i in inputHandlers ) { this.interactiveItems.add( inputHandlers[i] ); }
}
Phaser.Input.prototype.releaseCapture = function() {
if ( !this[property] ) return;
this.interactiveItems = this[property].inputStack.pop();
this[property].captor = undefined;
}
})('_input_captor_');
@lardratboy
Copy link
Author

My implementation of a setCapture/releaseCapture stack for Phaser.InputHandlers, put somewhere in your javascript after the Phaser module has been initialized.

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