Skip to content

Commit 6ed695c

Browse files
author
pandamicro
committed
Fix wechat touch end/cancel not fired issue
1 parent 34715e7 commit 6ed695c

File tree

3 files changed

+35
-2
lines changed

3 files changed

+35
-2
lines changed

CCBoot.js

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2020,6 +2020,21 @@ var _initSys = function () {
20202020
sys.openURL = function(url){
20212021
window.open(url);
20222022
};
2023+
2024+
/**
2025+
* Get the number of milliseconds elapsed since 1 January 1970 00:00:00 UTC.
2026+
* @memberof cc.sys
2027+
* @name now
2028+
* @return {Number}
2029+
*/
2030+
sys.now = function () {
2031+
if (Date.now) {
2032+
return Date.now();
2033+
}
2034+
else {
2035+
return +(new Date);
2036+
}
2037+
};
20232038
};
20242039
_initSys();
20252040

cocos2d/core/event-manager/CCTouch.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@
3333
* @param {Number} id
3434
*/
3535
cc.Touch = cc.Class.extend(/** @lends cc.Touch# */{
36+
_lastModified: 0,
3637
_point:null,
3738
_prevPoint:null,
3839
_id:0,

cocos2d/core/platform/CCInputManager.js

Lines changed: 19 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,8 @@ cc.UIInterfaceOrientationPortrait = 0;
5656
* @name cc.inputManager
5757
*/
5858
cc.inputManager = /** @lends cc.inputManager# */{
59+
TOUCH_TIMEOUT: 5000,
60+
5961
_mousePressed: false,
6062

6163
_isRegisterEvent: false,
@@ -81,12 +83,21 @@ cc.inputManager = /** @lends cc.inputManager# */{
8183

8284
_getUnUsedIndex: function () {
8385
var temp = this._indexBitsUsed;
86+
var now = cc.sys.now();
8487

8588
for (var i = 0; i < this._maxTouches; i++) {
8689
if (!(temp & 0x00000001)) {
8790
this._indexBitsUsed |= (1 << i);
8891
return i;
8992
}
93+
else {
94+
var touch = this._touches[i];
95+
if (now - touch._lastModified > this.TOUCH_TIMEOUT) {
96+
this._removeUsedIndexBit(i);
97+
delete this._touchesIntegerDict[touch.getID()];
98+
return i;
99+
}
100+
}
90101
temp >>= 1;
91102
}
92103

@@ -110,7 +121,9 @@ cc.inputManager = /** @lends cc.inputManager# */{
110121
* @param {Array} touches
111122
*/
112123
handleTouchesBegin: function (touches) {
113-
var selTouch, index, curTouch, touchID, handleTouches = [], locTouchIntDict = this._touchesIntegerDict;
124+
var selTouch, index, curTouch, touchID,
125+
handleTouches = [], locTouchIntDict = this._touchesIntegerDict,
126+
now = cc.sys.now();
114127
for(var i = 0, len = touches.length; i< len; i ++){
115128
selTouch = touches[i];
116129
touchID = selTouch.getID();
@@ -124,6 +137,7 @@ cc.inputManager = /** @lends cc.inputManager# */{
124137
}
125138
//curTouch = this._touches[unusedIndex] = selTouch;
126139
curTouch = this._touches[unusedIndex] = new cc.Touch(selTouch._point.x, selTouch._point.y, selTouch.getID());
140+
curTouch._lastModified = now;
127141
curTouch._setPrevPoint(selTouch._prevPoint);
128142
locTouchIntDict[touchID] = unusedIndex;
129143
handleTouches.push(curTouch);
@@ -142,7 +156,9 @@ cc.inputManager = /** @lends cc.inputManager# */{
142156
* @param {Array} touches
143157
*/
144158
handleTouchesMove: function(touches){
145-
var selTouch, index, touchID, handleTouches = [], locTouches = this._touches;
159+
var selTouch, index, touchID,
160+
handleTouches = [], locTouches = this._touches,
161+
now = cc.sys.now();
146162
for(var i = 0, len = touches.length; i< len; i ++){
147163
selTouch = touches[i];
148164
touchID = selTouch.getID();
@@ -155,6 +171,7 @@ cc.inputManager = /** @lends cc.inputManager# */{
155171
if(locTouches[index]){
156172
locTouches[index]._setPoint(selTouch._point);
157173
locTouches[index]._setPrevPoint(selTouch._prevPoint);
174+
locTouches[index]._lastModified = now;
158175
handleTouches.push(locTouches[index]);
159176
}
160177
}

0 commit comments

Comments
 (0)