本文整理汇总了C++中CCNode::ccTouchCaptureBegan方法的典型用法代码示例。如果您正苦于以下问题:C++ CCNode::ccTouchCaptureBegan方法的具体用法?C++ CCNode::ccTouchCaptureBegan怎么用?C++ CCNode::ccTouchCaptureBegan使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类CCNode
的用法示例。
在下文中一共展示了CCNode::ccTouchCaptureBegan方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: ccTouchesBegan
void CCScene::ccTouchesBegan(CCSet *pTouches, CCEvent *pEvent)
{
if (!m_touchDispatchingEnabled) return;
// cleanup
m_touchingTargets->removeAllObjects();
// sort touchable nodes
sortAllTouchableNodes(m_touchableNodes);
// find touching target
bool isTouchable = true;
CCObject *obj = NULL;
CCNode *node = NULL;
CCNode *checkTouchableNode = NULL;
CCTouchTargetNode *touchTarget = NULL;
CCARRAY_FOREACH(m_touchableNodes, obj)
{
checkTouchableNode = node = dynamic_cast<CCNode*>(obj);
// check node is visible and capturing enabled
isTouchable = true;
do
{
isTouchable = isTouchable
&& checkTouchableNode->isRunning()
&& checkTouchableNode->isVisible()
&& checkTouchableNode->isTouchCaptureEnabled();
checkTouchableNode = checkTouchableNode->getParent();
} while (checkTouchableNode && isTouchable);
if (!isTouchable) continue;
// prepare for touch testing
touchTarget = NULL;
const CCRect boundingBox = node->getCascadeBoundingBox();
// set touch target
CCTouch *touch = NULL;
for (CCSetIterator it = pTouches->begin(); it != pTouches->end(); ++it)
{
touch = (CCTouch*)*it;
const CCPoint touchPoint = touch->getLocation();
if (boundingBox.containsPoint(touchPoint))
{
if (!touchTarget)
{
touchTarget = CCTouchTargetNode::create(node);
}
if (touchTarget->getTouchMode() == kCCTouchesOneByOne)
{
touchTarget->setTouchId(touch->getID());
break;
}
}
}
if (!touchTarget)
{
// touch points not in current target, try to next
continue;
}
// try to dispatching event
CCArray *path = CCArray::createWithCapacity(10);
node = touchTarget->getNode();
do
{
path->addObject(node);
node = node->getParent();
} while (node != NULL && node != this);
// phase: capturing
// from parent to child
bool dispatchingContinue = true;
int touchMode = touchTarget->getTouchMode();
for (int i = path->count() - 1; dispatchingContinue && i >= 0; --i)
{
node = dynamic_cast<CCNode*>(path->objectAtIndex(i));
if (touchMode == kCCTouchesAllAtOnce)
{
node->ccTouchesCaptureBegan(pTouches, touchTarget->getNode());
}
else
{
dispatchingContinue = node->ccTouchCaptureBegan(touchTarget->findTouch(pTouches), touchTarget->getNode());
}
}
if (!dispatchingContinue)
{
// the target stop dispatching, try to next
continue;
}
// phase: targeting
node = touchTarget->getNode();
bool ret = true;
//.........这里部分代码省略.........