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 拖动指定层
最新推荐文章于 2019-03-21 15:53:53 发布