本文整理汇总了C++中CCLayer::ccTouchMoved方法的典型用法代码示例。如果您正苦于以下问题:C++ CCLayer::ccTouchMoved方法的具体用法?C++ CCLayer::ccTouchMoved怎么用?C++ CCLayer::ccTouchMoved使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类CCLayer
的用法示例。
在下文中一共展示了CCLayer::ccTouchMoved方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: onTouchMoved
void WHScrollView::onTouchMoved(cocos2d::Touch *pTouch, cocos2d::Event *pEvent)
{
if (m_PointerId != pTouch->getID())
return;
if (m_MoveCount < 8)
m_MoveCount++;
//CCScrollView::ccTouchMoved(pTouch, pEvent);
if (!isVisible())
return;
if (m_bScroll)
{
//if (_touches->containsObject(pTouch))
if (std::find(_touches.begin(), _touches.end(), pTouch) != _touches.end())
{
if (_touches.size() == 1 && _dragging)
{ // scrolling
CCPoint moveDistance, newPoint, maxInset, minInset;
CCRect frame;
float newX, newY;
_touchMoved = true;
CCPoint frameOriginal = getParent()->convertToWorldSpace(getPosition());
//frame = CCRectMake(frameOriginal.x, frameOriginal.y, m_tViewSize.width, m_tViewSize.height);
frame = CCRectMake(0, 0, _viewSize.width, _viewSize.height);
newPoint = convertTouchToNodeSpace((CCTouch*)_touches[0]);
moveDistance = ccpSub(newPoint, _touchPoint);
_touchPoint = newPoint;
CCSize contentsize = getContentSize();
CCPoint offset = getContentOffset();
if (offset.y <= _viewSize.height - contentsize.height)
{
moveDistance.y = moveDistance.y / m_MoveCount;
}
//if (frame.containsPoint(convertToWorldSpace(newPoint)))
if (frame.containsPoint(newPoint))
{
switch (_direction)
{
case ScrollView::Direction::VERTICAL:
moveDistance = ccp(0.0f, moveDistance.y);
break;
case ScrollView::Direction::HORIZONTAL:
moveDistance = ccp(moveDistance.x, 0.0f);
break;
default:
break;
}
_container->setPosition(ccpAdd(_container->getPosition(), moveDistance));
maxInset = _maxInset;
minInset = _minInset;
//check to see if offset lies within the inset bounds
newX = MIN(_container->getPosition().x, maxInset.x);
newX = MAX(newX, minInset.x);
newY = MIN(_container->getPosition().y, maxInset.y);
newY = MAX(newY, minInset.y);
_scrollDistance = ccpSub(moveDistance, ccp(newX - _container->getPosition().x, newY - _container->getPosition().y));
setContentOffset(ccp(newX, newY));
}
}
else if (_touches.size() == 2 && !_dragging)
{
const float len = ccpDistance(_container->convertTouchToNodeSpace((CCTouch*)_touches[0]),_container->convertTouchToNodeSpace((CCTouch*)_touches[1]));
setZoomScale(getZoomScale()*len / _touchLength);
}
}
}
for (int i = 0; i < m_TouchLayer.size(); i++)
{
if (m_TouchLayerTouched[i])
{
CCLayer* pTouchLayer = m_TouchLayer[i];
pTouchLayer->ccTouchMoved(pTouch, pEvent);
}
}
//CCScrollView::ccTouchMoved(pTouch, pEvent);
}