Develop and Download Open Source Software

Browse Subversion Repository

Diff of /trunk/src/js/jgame.js

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

revision 64 by tsugehara, Sun Mar 17 12:55:47 2013 UTC revision 66 by tsugehara, Fri Mar 22 03:41:17 2013 UTC
# Line 2054  var InputKeyboardEvent = (function (_sup Line 2054  var InputKeyboardEvent = (function (_sup
2054  })(InputEvent);  })(InputEvent);
2055  var InputPointEvent = (function (_super) {  var InputPointEvent = (function (_super) {
2056      __extends(InputPointEvent, _super);      __extends(InputPointEvent, _super);
2057      function InputPointEvent(e, entity, scale) {      function InputPointEvent(e, entity, point) {
2058          _super.call(this, InputEventType.Point, e);          _super.call(this, InputEventType.Point, e);
2059          var entityOffset = entity.offset();          var entityOffset = entity.offset();
2060          this.entity = entity;          this.entity = entity;
2061          this.point = {          this.point = point;
             x: scale ? e.offsetX / scale : e.offsetX,  
             y: scale ? e.offsetY / scale : e.offsetY  
         };  
2062          this.x = this.point.x - entityOffset.x;          this.x = this.point.x - entityOffset.x;
2063          this.y = this.point.y - entityOffset.y;          this.y = this.point.y - entityOffset.y;
2064      }      }
# Line 2520  var Game = (function () { Line 2517  var Game = (function () {
2517          }          }
2518      };      };
2519      Game.prototype.refresh = function () {      Game.prototype.refresh = function () {
         try  {  
             if(this.isTouchEnable()) {  
                 this.renderer.handler.removeEventListener("touchstart", this.onmousedown, false);  
                 this.renderer.handler.removeEventListener("touchmove", this.onmousemove, false);  
                 this.renderer.handler.removeEventListener("touchend", this.onmouseup, false);  
             } else {  
                 this.renderer.handler.removeEventListener("mousedown", this.onmousedown, false);  
                 this.renderer.handler.removeEventListener("mousemove", this.onmousemove, false);  
                 this.renderer.handler.removeEventListener("mouseup", this.onmouseup, false);  
             }  
         } catch (ex) {  
         }  
2520          this.renderer.refresh();          this.renderer.refresh();
2521          for(var i = 0; i < this.scenes.length; i++) {          for(var i = 0; i < this.scenes.length; i++) {
2522              this.scenes[i].refresh();              this.scenes[i].refresh();
2523          }          }
         this.pointHandler();  
2524      };      };
2525      Game.prototype.isTouchEnable = function () {      Game.prototype.isTouchEnable = function () {
2526          var div = document.createElement('div');          var div = document.createElement('div');
2527          div.setAttribute('ontouchstart', 'return');          div.setAttribute('ontouchstart', 'return');
2528          return typeof div.ontouchstart === 'function';          return typeof div.ontouchstart === 'function';
2529      };      };
2530        Game.prototype.getOffsetByEvent = function (e) {
2531            if(e.offsetX === undefined) {
2532                e.offsetX = e.layerX;
2533                e.offsetY = e.layerY;
2534            }
2535            if(JGUtil.isStyleScale) {
2536                return {
2537                    x: this.scale ? e.offsetX / this.scale : e.offsetX,
2538                    y: this.scale ? e.offsetY / this.scale : e.offsetY
2539                };
2540            }
2541            return {
2542                x: e.offsetX,
2543                y: e.offsetY
2544            };
2545        };
2546      Game.prototype.onmousedown = function (e) {      Game.prototype.onmousedown = function (e) {
2547          var layers = this.scene.getLayerArray();          var layers = this.scene.getLayerArray();
2548          var layer;          var layer;
2549          var offset = {          var offset = this.getOffsetByEvent(e);
             x: this.scale ? e.offsetX / this.scale : e.offsetX,  
             y: this.scale ? e.offsetY / this.scale : e.offsetY  
         };  
2550          while(layer = layers.pop()) {          while(layer = layers.pop()) {
2551              if(!layer.pointCapture) {              if(!layer.pointCapture) {
2552                  continue;                  continue;
# Line 2558  var Game = (function () { Line 2555  var Game = (function () {
2555              if(!dragObj) {              if(!dragObj) {
2556                  dragObj = layer;                  dragObj = layer;
2557              }              }
2558              this.dragParam = new InputPointEvent(e, dragObj, this.scale);              this.dragParam = new InputPointEvent(e, dragObj, offset);
2559              this.pointDown.fire(this.dragParam);              this.pointDown.fire(this.dragParam);
2560              if(this.scene.pointDown) {              if(this.scene.pointDown) {
2561                  this.scene.pointDown.fire(this.dragParam);                  this.scene.pointDown.fire(this.dragParam);
# Line 2578  var Game = (function () { Line 2575  var Game = (function () {
2575              var touch = touches[i];              var touch = touches[i];
2576              touch.offsetX = touch.pageX - this.renderer._pageX;              touch.offsetX = touch.pageX - this.renderer._pageX;
2577              touch.offsetY = touch.pageY - this.renderer._pageY;              touch.offsetY = touch.pageY - this.renderer._pageY;
2578              var offset = {              var offset = this.getOffsetByEvent(touch);
                 x: this.scale ? touch.offsetX / this.scale : touch.offsetX,  
                 y: this.scale ? touch.offsetY / this.scale : touch.offsetY  
             };  
2579              while(layer = layers.pop()) {              while(layer = layers.pop()) {
2580                  if(!layer.pointCapture) {                  if(!layer.pointCapture) {
2581                      continue;                      continue;
# Line 2590  var Game = (function () { Line 2584  var Game = (function () {
2584                  if(!dragObj) {                  if(!dragObj) {
2585                      dragObj = layer;                      dragObj = layer;
2586                  }                  }
2587                  this.dragParam = new InputPointEvent(touch, dragObj, this.scale);                  this.dragParam = new InputPointEvent(touch, dragObj, offset);
2588                  this.pointDown.fire(this.dragParam);                  this.pointDown.fire(this.dragParam);
2589                  if(this.scene.pointDown) {                  if(this.scene.pointDown) {
2590                      this.scene.pointDown.fire(this.dragParam);                      this.scene.pointDown.fire(this.dragParam);
# Line 2607  var Game = (function () { Line 2601  var Game = (function () {
2601          if(!this.dragParam) {          if(!this.dragParam) {
2602              return;              return;
2603          }          }
2604          var param = new InputPointEvent(e, this.dragParam.entity, this.scale);          var param = new InputPointEvent(e, this.dragParam.entity, this.getOffsetByEvent(e));
2605          if(this.dragParam.entity.pointMove) {          if(this.dragParam.entity.pointMove) {
2606              this.dragParam.entity.pointMove.fire(param);              this.dragParam.entity.pointMove.fire(param);
2607          }          }
# Line 2626  var Game = (function () { Line 2620  var Game = (function () {
2620              var touch = touches[i];              var touch = touches[i];
2621              touch.offsetX = touch.pageX - this.renderer._pageX;              touch.offsetX = touch.pageX - this.renderer._pageX;
2622              touch.offsetY = touch.pageY - this.renderer._pageY;              touch.offsetY = touch.pageY - this.renderer._pageY;
2623              var param = new InputPointEvent(touch, this.dragParam.entity, this.scale);              var offset = this.getOffsetByEvent(touch);
2624                var param = new InputPointEvent(touch, this.dragParam.entity, offset);
2625              if(this.dragParam.entity.pointMove) {              if(this.dragParam.entity.pointMove) {
2626                  this.dragParam.entity.pointMove.fire(param);                  this.dragParam.entity.pointMove.fire(param);
2627              }              }
# Line 2641  var Game = (function () { Line 2636  var Game = (function () {
2636          if(!this.dragParam) {          if(!this.dragParam) {
2637              return;              return;
2638          }          }
2639          var param = new InputPointEvent(e, this.dragParam.entity, this.scale);          var param = new InputPointEvent(e, this.dragParam.entity, this.getOffsetByEvent(e));
2640          if(this.dragParam.entity.pointUp) {          if(this.dragParam.entity.pointUp) {
2641              this.dragParam.entity.pointUp.fire(param);              this.dragParam.entity.pointUp.fire(param);
2642          }          }
# Line 2661  var Game = (function () { Line 2656  var Game = (function () {
2656              var touch = touches[i];              var touch = touches[i];
2657              touch.offsetX = touch.pageX - this.renderer._pageX;              touch.offsetX = touch.pageX - this.renderer._pageX;
2658              touch.offsetY = touch.pageY - this.renderer._pageY;              touch.offsetY = touch.pageY - this.renderer._pageY;
2659              var param = new InputPointEvent(touch, this.dragParam.entity, this.scale);              var offset = this.getOffsetByEvent(touch);
2660                var param = new InputPointEvent(touch, this.dragParam.entity, offset);
2661              if(this.dragParam.entity.pointUp) {              if(this.dragParam.entity.pointUp) {
2662                  this.dragParam.entity.pointUp.fire(param);                  this.dragParam.entity.pointUp.fire(param);
2663              }              }
# Line 4516  var JGUtil = (function () { Line 4512  var JGUtil = (function () {
4512          var context = canvas.getContext("2d");          var context = canvas.getContext("2d");
4513          return context.createPattern(image, repeat == undefined ? "repeat" : repeat);          return context.createPattern(image, repeat == undefined ? "repeat" : repeat);
4514      };      };
4515        JGUtil.isTransformMode = function isTransformMode() {
4516            if(JGUtil.isStyleScale === undefined) {
4517                var test = document.createElement("canvas");
4518                JGUtil.isStyleScale = test.style['webkitTransform'] === undefined;
4519            }
4520            return !JGUtil.isStyleScale;
4521        };
4522      JGUtil.scaleCanvas = function scaleCanvas(canvas, size) {      JGUtil.scaleCanvas = function scaleCanvas(canvas, size) {
4523          if(canvas.style['webkitTransform'] !== undefined) {          if(JGUtil.isTransformMode()) {
4524              canvas.style['webkitTransformOrigin'] = '0 0';              canvas.style['webkitTransformOrigin'] = '0 0';
4525              canvas.style['webkitTransform'] = 'scale(' + Math.max(size.width / canvas.width, size.height / canvas.height) + ')';              canvas.style['webkitTransform'] = 'scale(' + Math.max(size.width / canvas.width, size.height / canvas.height) + ')';
4526          } else {          } else {

Legend:
Removed from v.64  
changed lines
  Added in v.66

Back to OSDN">Back to OSDN
ViewVC Help
Powered by ViewVC 1.1.26