cocos2dx2 2.2 拖动指定层

 setTouchEnabled(true);
void ToolAssembleLayer::ccTouchesBegan( CCSet *pTouches, CCEvent *pEvent )
{
	CCSetIterator it = pTouches->begin();
	CCTouch* touch = (CCTouch*)(*it);
	oldPoint = touch->getLocation();
	//return true;
}

void ToolAssembleLayer::ccTouchesMoved( CCSet *pTouches, CCEvent *pEvent )
{
	CCSetIterator it = pTouches->begin();
	CCTouch* touch = (CCTouch*)(*it);

	if ( !containsTouchLocation(touch) )
	{
		oldPoint = touch->getLocation();
		return;
	}

	this->setPosition(CCPoint(this->getPositionX()+ touch->getLocation().x-oldPoint.x, this->getPositionY()));
	oldPoint = touch->getLocation();
}

CCRect ToolAssembleLayer::rect()
{
	CCSize s = this->getContentSize();
	return CCRectMake(-s.width/2 , -s.height , s.width/2, s.height/2);
}
bool ToolAssembleLayer::containsTouchLocation(CCTouch* touch)
{
	return rect().containsPoint(convertTouchToNodeSpaceAR(touch));
}

你可能感兴趣的:(cocos2dx2 2.2 拖动指定层)