bool MainGame::onTouchBegan(Touch * touch,Event * pEvent)
{
auto point = touch->getLocation();
auto rect = getChildByTag(110)->getBoundingBox();
if(rect.containsPoint(point))
return true;
return false;
}
void MainGame::onTouchMoved(Touch * touch,Event * pEvent)
{
auto addPoint = touch->getLocation()-touch->getPreviousLocation();
getChildByTag(110)->setPosition(getChildByTag(110)->getPosition()+addPoint);
}
```
怎么改成只是上下拖动,无需自由移动
CCPoint curP = CCDirector::sharedDirector()->convertToGL(touch->getLocationInView());
CCPoint lastP =touch->getPreviousLocation();
CCPoint translation=ccpSub(curP, lastP);
getChildByTag(110)->setPosition(ccpAdd(getChildByTag(110)->getPosition(),translation));
设y坐标不行吗
可以将addPoint的X设置为0, 但我不会设置啊,求教
貌似这样还是可以随意拖动啊
重写Sprite类 实现触摸判断触摸是否在Sprite上面 想上下拖动 或者左右拖动 或者是 随意拖动 用个控制函数设定即可0.0
getChildByTag(110)->setPositionY() 这样不行吗?