触摸移动的太快时,精灵跟不上,请问有什么办法解决?

各位大神 ,在onTouchMoved 中 点击精灵跟随鼠标移动。。。
但是触摸移动的太快时,精灵跟不上,请问有什么办法解决?

:10:

不知道楼主是怎么实现的,可以贴下代码。

谢谢回复,,,代码如下
void cmtest::onTouchMoved(CCTouch * touch,CCEvent* event)
{

     Point locationInNode = plane->convertToNodeSpace(touch->getLocation());  
    Size s = plane->getContentSize();  
    Rect rect = Rect(0, 0, s.width, s.height);  
    if (rect.containsPoint(locationInNode))//判断触摸点是否在目标的范围内              
    {
        if (isControl)
            {
                CCPoint location = touch->getLocationInView();
                location = CCDirector::sharedDirector()->convertToGL(location);
                float x = location.x - deltax;
                float y = location.y - deltay;
                plane->setPosition(ccp(x,y));   //主角精灵位置
                 
            } 
    }
    else  
        {//  return false;  
    } 

}

你把手指是否在指定的区域内的判断放到了move中来判断,这个时候if返回的结果就不一定为true了,所以就达不到设置坐标的目的了。可以参考这个代码。
bool HelloWorld::ccTouchBegan(CCTouch * touch,CCEvent * pEvent)
{
CCSprite * sprite = (CCSprite *)this->getChildByTag(0);
//获得手指点击的点的坐标
CCPoint point = touch->getLocation();
//获得精灵所在的区域,CCRect包括x,y,width,height
CCRect rect = sprite->boundingBox();

//判断手指点击的点是否点在了精灵上
if(rect.containsPoint(point))
{
    //返回true则会接受其他的协议消息
    return true;
}

return false;

}

void HelloWorld::ccTouchMoved(CCTouch * touch,CCEvent * pEvent)
{
/*
这里可以直接将精灵的坐标设置为手指所在点的坐标位置,但是这样的话会产生跳跃的效果,视觉上不好看,这是
因为精灵是在用自己的锚点占据我们设置的坐标位置,而不是我们点击在精灵身上的那个点放到我们的手指所在的位置
*/

//分别获得了手指现在的点击点和手指上次的点击点位置
CCPoint point = touch->getLocation();
CCPoint pointPre = touch->getPreviousLocation();
//ccpSub将俩个点相减,获得一个移动方向的向量
CCPoint direction = ccpSub(point,pointPre);

CCSprite * sprite = (CCSprite *)this->getChildByTag(0);
CCPoint spritePoint = sprite->getPosition();
//ccpAdd将精灵现在的位置点和移动方向的向量相加,获得精灵将要移动到的位置点
CCPoint spriteDirection = ccpAdd(spritePoint,direction);
sprite->setPosition(spriteDirection);

}

路过 学习一下 别打扰我:5::5::5:

滑动太快会进cctouchended里面,不信你输出看看