cocos2d-x 实现地图随双指移动
更新:HHH   时间:2023-1-7


voidBattleView::ccTouchesBegan(CCSet *pTouches,CCEvent *pEvent)

{

//CCSet的迭代器

CCSetIterator iter = pTouches->begin();

//迭代出pTouches所有Touches

for (;iter!= pTouches->end();iter++)

   {

//取出Touches

CCTouch* pTouch = (CCTouch*)(*iter);

//得到取出的Touch的位置坐标

CCPoint location = pTouch->getLocation();


//保存第一个点坐标

if (pTouch->getID()==0)

       {

m_Point1 = location;

initialD = true;


       }

//第二个点,保存坐标

if (pTouch->getID()==1&& initialD ==true)

       {

m_Point2 = location;

m_beganLocation = location;

       }

   }

}

voidBattleView::ccTouchesMoved(CCSet *pTouches,CCEvent *pEvent)

{

CCSetIterator iter = pTouches->begin();

for (;iter!=pTouches->end();iter++)

   {

CCTouch* pTouch = (CCTouch*)(*iter);

//得到触摸点的坐标

CCPoint location = pTouch->getLocation();


if (pTouch->getID()==0)

           {

               movePoint1 = location;

           }

if (pTouch->getID()==1)

           {

               movePoint2 = location;

         m_endLocation = location;

CCPoint moveTo=ccpSub(m_endLocation, m_beganLocation);

m_beganLocation=m_endLocation;

m_BattleWorld->setPosition(ccpAdd(m_BattleWorld->getPosition(), moveTo));

}

}

这里解决了屏幕闪的问题,想想为什么呢?


返回游戏开发教程...