Created
November 15, 2011 22:35
-
-
Save timkim/1368596 to your computer and use it in GitHub Desktop.
Quick fix for scope
This file contains hidden or 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
// Try setting var self = this in the init and using self.mouseX/self.mouseY in onMouseMove | |
GAME.Input = function ( parent ) { | |
this.game = parent; | |
this.oldMouseX = 0; | |
this.oldMouseY = 0; | |
this.mouseX = 0; | |
this.mouseY = 0; | |
}; | |
GAME.Input.prototype = { | |
init: function ( useMouse, useKeyboard ) { | |
var self = this; | |
if ( useMouse == true) { | |
document.addEventListener( 'mousemove', this.onMouseMove, false ); | |
this.write("Mouse move listener started"); | |
} | |
}, | |
update: function () { | |
if (this.mouseX != this.oldMouseX || this.mouseY != this.oldMouseY) { | |
this.oldMouseX = this.mouseX; | |
this.oldMouseY = this.mouseY; | |
this.write(this.mouseX + " x " + this.mouseY); | |
} | |
}, | |
onMouseMove: function ( event ) { | |
self.mouseX = event.clientX; | |
self.mouseY = event.clientY; | |
}, | |
write: function ( info, color ) { | |
this.game.config.write( 'Input > ' + info, color ); | |
}, | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment