前面已经写过一篇了,在这里就不具体解释细节了,大体原理都是一样的,双指缩放还是根据双指间占原距离的比例进行缩放。下面直接上代码了:
.h
#ifndef __MAPLAYER_H
#define __MAPLAYER_H
#include "cocos2d.h"
using namespace cocos2d;
class MapLayer:public Layer
{
public:
Vec2 mpOrigin;
virtual bool init();
CREATE_FUNC(MapLayer);
private:
};
#endif // !__MAPLAYER_H
下面是 .cpp 注释写的很详细不明白的话可以细看
auto dis = Director::getInstance()->getEventDispatcher();
auto listen = EventListenerTouchAllAtOnce::create();
listen->onTouchesMoved = [=](const std::vector<Touch*>& touches, Event *event){
if(touches.size() > 1) // 多点进行缩放
{
// 得到当前两触摸点
auto point1 = touches[0]->getLocation();
auto point2 = touches[1]->getLocation();
// 计算两点之间得距离
auto currDistance = point1.distance(point2);
// 计算两触摸点上一时刻之间得距离
auto prevDistance =