Cocos2d-x 让精灵随手指移动起来二(简单实现)

void HelloWorld::ccTouchMoved(cocos2d::CCTouch *touch, cocos2d::CCEvent *event)
{

	CCSize winSize = CCDirector::sharedDirector()->getVisibleSize();
	if (m_ship) {
		CCPoint pos = touch->getDelta();//获取触点当前位置与较早前的位置的差距
		CCPoint currentPos = m_ship->getPosition();//精灵坐标
		currentPos = ccpAdd(currentPos, pos);//精灵加触摸坐标
		currentPos = ccpClamp(currentPos, CCPointZero, ccp(winSize.width, winSize.height));//限制精灵出屏幕
		m_ship->setPosition(currentPos);//重设精灵坐标
	}
}

原文地址:https://www.cnblogs.com/mengfanrong/p/3767633.html