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);//重设精灵坐标
	}
}

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

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

上一篇:Android核心基础第五天


下一篇:android Snake(3)