您的位置:首页 > 移动开发 > Cocos引擎

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

2014-05-26 23:59 369 查看
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);//重设精灵坐标
	}
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: