我正在尝试获得类似飞行控制游戏的效果。用户在屏幕上拖动手指,它将数据存储在一个数组中,然后项目沿着该路径到达手指被抬起的位置。
我有这个工作的代码,我的问题是我希望它像在游戏中一样保持稳定的速度,当我的精灵移动时,它的速度会随着你手指移动的速度而变化。
任何帮助,将不胜感激。
我相当肯定这与我的 CCMoveTo 操作有关,但我真的想不出任何其他方法来做到这一点。
void WavePrototypeInterface::ccTouchesBegan(CCSet* touches, CCEvent* event)
{
while (movementPath->count() != 0)
{
movementPath->removeControlPointAtIndex(0);
}
index=0;
this->stopAllActions();
}
void WavePrototypeInterface::ccTouchesMoved(CCSet* touches, CCEvent* event)
{
CCTouch* touch = (CCTouch*)( touches->anyObject() );
CCPoint location = touch->getLocationInView();
location = CCDirector::sharedDirector()->convertToGL(location);
movementPath->addControlPoint(location);
int xValue = movementPath->count();
}
void WavePrototypeInterface::ccTouchesEnded(CCSet* touches, cocos2d::CCEvent* event)
{
if(!movementPath->count()<=0)
{
goToPointWithIndex();
}
}
void WavePrototypeInterface::goToPointWithIndex()
{
CCPoint toPoint = movementPath->getControlPointAtIndex(index);
if(index < movementPath->count())
{
index++;
sprite->setPosition(toPoint);
CCDelayTime * delay = CCDelayTime::create(0.1);
CCCallFunc *func = CCCallFunc::create(this, callfunc_selector(WavePrototypeInterface::goToPointWithIndex));
CCSequence * seq = CCSequence::createWithTwoActions(delay, func);
this->runAction(seq);
}
}