码迷,mamicode.com
首页 > 移动开发 > 详细

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

时间:2014-06-05 05:25:10      阅读:222      评论:0      收藏:0      [点我收藏+]

标签:c   class   blog   code   a   int   

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 让精灵随手指移动起来二(简单实现)

标签:c   class   blog   code   a   int   

原文地址:http://blog.csdn.net/oyangyufu/article/details/27123547

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!