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

时间:2014-06-05 05:25:10   收藏:0   阅读:222
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);//重设精灵坐标
	}
}

Cocos2d-x 让精灵随手指移动起来二(简单实现),布布扣,bubuko.com

评论(0
© 2014 mamicode.com 版权所有 京ICP备13008772号-2  联系我们:gaon5@hotmail.com
迷上了代码!