I am working on game built in Cocos2d-x, was going fine till I tested it on iPhone 6S Plus. On this particular device CCTouchesMoved is called multiple times even on single tap event while its works fine on other iOS devices, can you help me out what I'm missing or is there anything changed in iPhone 6S plus ?
void CCLayerPanZoom::ccTouchesBegan(cocos2d::CCSet *pTouches, cocos2d::CCEvent *pEvent) {
CCLOG("CCLayerPanZoom::ccTouchesBegan");
}
void CCLayerPanZoom::ccTouchesMoved(cocos2d::CCSet *pTouches, cocos2d::CCEvent *pEvent) {
CCLOG("CCLayerPanZoom::ccTouchesMoved");
}
Here, ccTouchesMoved
is called multiple times, which is not normal behavior and also doesn't happen on other iOS devices.
I found the answer here
As the launch of iPhone 6s /6s plus, a new technology called '3D Touch' is introduced. The day when I got my new iPhone 6s, I tested my game on it.
Everything works just fine for me, but: 1. Sometimes touch events just wouldn't work. 2. Sometimes touch events work ridiculously.
After a week of problem shooting, I finally find: The function of 'onTouchMoved' will be called sometimes even if the touch location in 2D does not change. Yes, touch location is now in 3D. And the touch location in z dimension is extremely sensitive (comparing with that in x and y dimensions). A very slight force applied from you finger to the screen could lead to the touch location to change in z dimension and make the game engine (cocos2d-x) to call the function of 'onTouchMoved'.
However, the latest version of cocos2d-x (till the post day of this topic: 2015/10/25) has not support 3D Touch yet. So you cannot access the z dimension, but get disturbed by it. If any of your game logic does only concerns about whether the touch location has changed in 2D, the function of 'onTouchMoved' is no longer reliable. Here is my solution:
Warn your player to touch the screen very slightly to avoid the change of touch location in z dimension frowning
Or, you can add code like below to avoid the code in 'onTouchMoved' function to be called unexpectedly:
void CCLayerPanZoom::ccTouchesMoved(cocos2d::CCSet *pTouches, cocos2d::CCEvent *pEvent) {
CCPoint point1 = touch->getLocation();
CCPoint point2 = touch->getPreviousLocation();
if (point1.equals(point2)) {
return;
}
CCLOG("CCLayerPanZoom::ccTouchesMoved");
}
getLocation() or getPreviousLocation() returns Vec2 values, so you can eliminate pretty safely the disturbance case by touch force parameter (touch moved in z dimension).
So, That's it.