在touchBegan中写入:
if (test->boundingBox().containsPoint(touchPoint))
{
btest = true;
distanceCpp = ccpSub(touchPoint,test->getPosition());
CCLOG("%lf,%lf",distanceCpp.x,distanceCpp.y);
return true;
}
test是精灵,distanceCpp是点击点和test的位置的距离
在touchMoce中
if (btest)
{
test->setPosition(ccpSub(touchPoint,distanceCpp));
}
在touchEnd中
btest = false;
这样的话,就可以根据点击位置来拖动精灵啦。