Adding Touch and Drag Events

134        /**
135         * addTouchAndDragEvents
136         * @param sprite
137         */
138        this.addTouchAndDragEvents = function(sprite) {
139          var scope = this.self.scope;
140  
141          if (sprite.node.isBackground) {
142            return;
143          }
144  
145          // allow it to respond to mouse and touch events
146          sprite.interactive = true;
147          // this button mode will mean the hand cursor appears when you rollover the sprite with your mouse
148          sprite.buttonMode = true;
149  
150          // setup mousedown and touchstart
151          sprite.mousedown = sprite.touchstart = function(data) {
152            if (scope.bbStates.canvasMode === 'edit') {
153              this.data = data;
154              this.alpha = 0.8;
155              this.dragging = true;
156              this.sx = this.data.getLocalPosition(sprite).x * sprite.scale.x;
157              this.sy = this.data.getLocalPosition(sprite).y * sprite.scale.y;
158            } else {
159              scope.fireTouchEvent(this, sprite.node);
160            }
161          };
162  
163          // setup release event
164          sprite.mouseup = sprite.mouseupoutside = sprite.touchend = sprite.touchendoutside = function(data) {
165            if (scope.bbStates.canvasMode === 'edit') {
166              this.alpha = 1;
167              this.dragging = false;
168              this.data = null;
169            }
170          };
171  
172          // set the callbacks for when the mouse or a touch moves
173          sprite.mousemove = sprite.touchmove = function(data) {
174            if (scope.bbStates.canvasMode === 'edit') {
175              var newPosition;
176              if (this.dragging) {
177                newPosition = this.data.getLocalPosition(this.parent);
178                this.position.x = newPosition.x - this.sx;
179                this.position.y = newPosition.y - this.sy;
180              }
181            }
182          };
183        };
184