不知道哪位有做过cocos2dx 3.0 多点触摸缩放,有参考http://blog.csdn.net/somestill/article/details/10581277的来实现,但在onTouchesBegan事件里一直只会捕到一个触点。
现在的实现方式是在onTouchesMoved里计算触摸前后两点距离算缩放比。但使用起来很不自然
auto listener = EventListenerTouchAllAtOnce::create(); listener->onTouchesBegan = CC_CALLBACK_2(WorldLayer::onTouchesBegan, this); listener->onTouchesMoved = CC_CALLBACK_2(WorldLayer::onTouchesMoved, this); listener->onTouchesEnded = CC_CALLBACK_2(WorldLayer::onTouchesEnded, this); _eventDispatcher->addEventListenerWithSceneGraphPriority(listener, sprite); void WorldLayer::onTouchesBegan(const std::vector& touches, Event *event) { //查看日志,在多点触摸时,只有一个点 log("world map touches began: size=%d", touches.size() ); } void WorldLayer::onTouchesMoved(const std::vector& touches, Event *event) { //缩放 if(touches.size() > 1) { auto distance1 = touches->getPreviousLocation().distance(touches->getPreviousLocation()); auto distance2 = touches->getLocation().distance(touches->getLocation()); float scale = sprite->getScale() * ( distance2 / distance1); scale = MIN(2,MAX(0.5, scale)); sprite->setScale(scale); log("world map touches moved: size=%d, d1=%f , d2=%f",touches.size() , distance1,distance2 ); } else { //移动地图 onTouchMoved(touches,event); } } void WorldLayer::onTouchesEnded(const std::vector& touches, Event* event) { log("world map touches ended: size=%d", touches.size() ); } ```