Resetting input handlers in EaselJS

I've been working on some stuff in EaselJS. Recently I typed up a little object to handle managing different Scene type things in a stage. Each scene inherits off a collection, but the superglobal inputs were bugging me, so I wrote this up to default out the input handlers and not have to worry about the game's scale.

In the game's resize I set the self's (just the this of the object) inverseScale to be equal to 1 / the original Canvas scale for each dimension.

It's been working well so far!

this.switchScene = function (newscene, retain) {

      if (self.currentScene) {
        if (!retain) {
          delete self.currentScene;
      self.currentScene = newscene;

      //reset input handlers
      (function (target) {
        ['onMouseDown', 'onMouseMove', 'onMouseUp', 'onPress', 'onClick'].map(
          function (inputType) {
            if (newscene.hasOwnProperty(inputType)) {
              target.stage[inputType] = function (event) {
                event.stageX *= self.inverseScale.x;
                event.stageY *= self.inverseScale.y;
                return newscene[inputType](event);
            } else {
              target.stage[inputType] = undefined;


Leave a Reply

Your email address will not be published. Required fields are marked *