当前位置: 首页>>代码示例>>C++>>正文


C++ CCLayer::ccTouchMoved方法代码示例

本文整理汇总了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);

}
开发者ID:zhangchu1994,项目名称:HelloWorldCpp3.5,代码行数:87,代码来源:WHScorllView.cpp


注:本文中的CCLayer::ccTouchMoved方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。