Skip to content

Commit

Permalink
fix #129
Browse files Browse the repository at this point in the history
  • Loading branch information
rtsan committed Feb 28, 2013
1 parent f47a153 commit 75eecad
Show file tree
Hide file tree
Showing 3 changed files with 62 additions and 58 deletions.
67 changes: 34 additions & 33 deletions dev/src/Entity.js
Expand Up @@ -135,39 +135,40 @@ enchant.Entity = enchant.Class.create(enchant.Node, {
}
}, false);
}
this._element.addEventListener('mousedown', function(e) {
var x = e.pageX;
var y = e.pageY;
e = new enchant.Event('touchstart');
e.identifier = game._mousedownID;
e._initPosition(x, y);
that.dispatchEvent(e);
that._mousedown = true;
}, false);
game._element.addEventListener('mousemove', function(e) {
if (!that._mousedown) {
return;
}
var x = e.pageX;
var y = e.pageY;
e = new enchant.Event('touchmove');
e.identifier = game._mousedownID;
e._initPosition(x, y);
that.dispatchEvent(e);
}, false);
game._element.addEventListener('mouseup', function(e) {
if (!that._mousedown) {
return;
}
var x = e.pageX;
var y = e.pageY;
e = new enchant.Event('touchend');
e.identifier = game._mousedownID;
e._initPosition(x, y);
that.dispatchEvent(e);
that._mousedown = false;
}, false);

if (enchant.ENV.MOUSE_ENABLED){
this._element.addEventListener('mousedown', function(e) {
var x = e.pageX;
var y = e.pageY;
e = new enchant.Event('touchstart');
e.identifier = game._mousedownID;
e._initPosition(x, y);
that.dispatchEvent(e);
that._mousedown = true;
}, false);
game._element.addEventListener('mousemove', function(e) {
if (!that._mousedown) {
return;
}
var x = e.pageX;
var y = e.pageY;
e = new enchant.Event('touchmove');
e.identifier = game._mousedownID;
e._initPosition(x, y);
that.dispatchEvent(e);
}, false);
game._element.addEventListener('mouseup', function(e) {
if (!that._mousedown) {
return;
}
var x = e.pageX;
var y = e.pageY;
e = new enchant.Event('touchend');
e.identifier = game._mousedownID;
e._initPosition(x, y);
that.dispatchEvent(e);
that._mousedown = false;
}, false);
}
},
/**
[lang:ja]
Expand Down
1 change: 1 addition & 0 deletions dev/src/Env.js
Expand Up @@ -36,6 +36,7 @@ enchant.ENV = {
div.setAttribute('ontouchstart', 'return');
return typeof div.ontouchstart === 'function';
}()),
MOUSE_ENABLED: true,
/**
* Is this browser iPhone with Retina display?
* @type {String}
Expand Down
52 changes: 27 additions & 25 deletions dev/src/Game.js
Expand Up @@ -371,34 +371,36 @@
}
}, true);
}
stage.addEventListener('mousedown', function(e) {
var tagName = (e.target.tagName).toLowerCase();
if (enchant.ENV.USE_DEFAULT_EVENT_TAGS.indexOf(tagName) === -1) {
e.preventDefault();
game._mousedownID++;
if (!game.running) {
e.stopPropagation();
if (enchant.ENV.MOUSE_ENABLED) {
stage.addEventListener('mousedown', function(e) {
var tagName = (e.target.tagName).toLowerCase();
if (enchant.ENV.USE_DEFAULT_EVENT_TAGS.indexOf(tagName) === -1) {
e.preventDefault();
game._mousedownID++;
if (!game.running) {
e.stopPropagation();
}
}
}
}, true);
stage.addEventListener('mousemove', function(e) {
var tagName = (e.target.tagName).toLowerCase();
if (enchant.ENV.USE_DEFAULT_EVENT_TAGS.indexOf(tagName) === -1) {
e.preventDefault();
if (!game.running) {
e.stopPropagation();
}, true);
stage.addEventListener('mousemove', function(e) {
var tagName = (e.target.tagName).toLowerCase();
if (enchant.ENV.USE_DEFAULT_EVENT_TAGS.indexOf(tagName) === -1) {
e.preventDefault();
if (!game.running) {
e.stopPropagation();
}
}
}
}, true);
stage.addEventListener('mouseup', function(e) {
var tagName = (e.target.tagName).toLowerCase();
if (enchant.ENV.USE_DEFAULT_EVENT_TAGS.indexOf(tagName) === -1) {
e.preventDefault();
if (!game.running) {
e.stopPropagation();
}, true);
stage.addEventListener('mouseup', function(e) {
var tagName = (e.target.tagName).toLowerCase();
if (enchant.ENV.USE_DEFAULT_EVENT_TAGS.indexOf(tagName) === -1) {
e.preventDefault();
if (!game.running) {
e.stopPropagation();
}
}
}
}, true);
}, true);
}
}
},
/**
Expand Down

0 comments on commit 75eecad

Please sign in to comment.