CCSetIterator iter = touches->begin();
for (; iter != touches->end(); iter++)
{
CCTouch* touchPoint = (CCTouch*)(*iter);
if(touchPoint->getID()==0)
{
CCLog("TOUCH_1");
location1 = touchPoint->getLocationInView();
location1 = CCDirector::sharedDirector()->convertToGL(location1);
}
if(touchPoint->getID()==1)
{
CCLog("TOUCH_2");
location2 = touchPoint->getLocationInView();
location2 = CCDirector::sharedDirector()->convertToGL(location2);
CCSprite* lightning = CCSprite::create("lightningFrame_0.png");
lightning->setScale(.4);
lightning->setPosition(ccp((location1.x+location2.x)/2,(location1.y+location2.y)/2));
lightning->setScaleX(ccpDistance(location1,location2)/1920);
this->addChild(lightning,0,0);
float angleRad = atanf((location2.y-location1.y)/(location2.x-location1.x));
float angleDeg = CC_RADIANS_TO_DEGREES(angleRad);
lightning->setRotation(-angleDeg);
addBoxBodyForSprite(lightning);
CCAction* removeChild = CCCallFuncN::create(this,callfuncN_selector(HelloWorld::spriteDone));
CCAction* fadeAway = CCFadeOut::create(.5);
lightning->runAction(CCSequence::create(animInt.lightningAnimation(), removeChild ,NULL));
lightning->runAction(fadeAway);
}
}
上面的代码获取了两个接触点,并在它们之间添加了一个闪电精灵。它在 Android 上运行完美,但在 iOS 上,有时会混淆位置 1 和位置 2。如果我像“驰骋”一样缓慢地应用 2 次触摸,它可以在 iOS 上运行。为什么会有这样的行为。这让我困惑了一周左右。任何信息都会很棒!