Permalink
Browse files

added mouse events. no touch events yet

  • Loading branch information...
1 parent 222c352 commit 5d1b0303d2687c5e4d70baafc99cb226df4af088 @davidsiaw davidsiaw committed Dec 4, 2011
Showing with 28 additions and 12 deletions.
  1. +21 −1 src/mwe/GameAction.js
  2. +7 −11 src/mwe/InputManager.js
View
22 src/mwe/GameAction.js
@@ -25,6 +25,8 @@ dojo.declare("mwe.GameAction",null,{
behavior: 0,
amount : 0,
state : 0,
+ x : -1,
+ y : -1,
statics: {
/**
@@ -42,7 +44,8 @@ dojo.declare("mwe.GameAction",null,{
STATE_RELEASED : 0,
STATE_PRESSED : 1,
- STATE_WAITING_FOR_RELEASE : 2
+ STATE_WAITING_FOR_RELEASE : 2,
+ STATE_MOVED : 3
},
/**
@@ -112,6 +115,14 @@ dojo.declare("mwe.GameAction",null,{
this.state = this.statics.STATE_RELEASED;
},
+ /**
+ Signals that a movement has occurred
+ */
+ move: function(x, y) {
+ this.x = x;
+ this.y = y;
+ },
+
/**
Returns whether the key was pressed or not since last
@@ -128,6 +139,15 @@ dojo.declare("mwe.GameAction",null,{
/**
+ Gets the current position of the mouse/touch if its registered
+ as a mouse/touch action
+ */
+ getPosition : function() {
+ var self = this;
+ return {x:self.x, y:self.y};
+ },
+
+ /**
For keys, this is the number of times the key was
pressed since it was last checked.
For mouse movement, this is the distance moved.
View
18 src/mwe/InputManager.js
@@ -71,32 +71,28 @@ dojo.declare("mwe.InputManager",null,{
},
- mouseUp: function(e){
-
-
+ mouseUp: function(e) {
+ this.mouseAction.release();
},
mouseDown: function(e){
-
-
+ this.mouseAction.press();
},
mouseMove: function(e){
-
+ this.mouseAction.move(e.clientX, e.clientY);
},
touchStart: function(e){
-
-
+ this.touchAction.press();
},
touchEnd: function(e){
-
-
+ this.touchAction.release();
},
touchMove: function(e){
-
+ this.touchAction.move(e.clientX, e.clientY);
},

0 comments on commit 5d1b030

Please sign in to comment.