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


C++ CCNode::ccTouchBegan方法代码示例

本文整理汇总了C++中CCNode::ccTouchBegan方法的典型用法代码示例。如果您正苦于以下问题:C++ CCNode::ccTouchBegan方法的具体用法?C++ CCNode::ccTouchBegan怎么用?C++ CCNode::ccTouchBegan使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在CCNode的用法示例。


在下文中一共展示了CCNode::ccTouchBegan方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。

示例1: ccTouchBegan

bool CCScene::ccTouchBegan(CCTouch *pTouch, CCEvent *pEvent)
{
    CC_SAFE_RELEASE_NULL(m_touchNode);
    const CCPoint p = pTouch->getLocation();
    CCObject *node;
    CCNode *touchNode = NULL;
    CCNode *checkNode = NULL;
    bool visible = true;
    sortAllTouchableNodes();
    CCARRAY_FOREACH(m_touchableNodes, node)
    {
        checkNode = touchNode = dynamic_cast<CCNode*>(node);

        // check node is visible
        visible = true;
        do
        {
            visible = visible && checkNode->isVisible();
            checkNode = checkNode->getParent();
        } while (checkNode && visible);
        if (!visible) continue;

        const CCRect boundingBox = touchNode->getCascadeBoundingBox();
        if (boundingBox.containsPoint(p))
        {
            touchNode->retain();
            bool ret = touchNode->ccTouchBegan(pTouch, pEvent);
            if (ret && touchNode->isRunning())
            {
                m_touchNode = touchNode;
                m_touchNode->retain();
            }
            touchNode->release();
            if (ret) return true;
        }
    }
开发者ID:SD216814,项目名称:quick-cocos2d-x,代码行数:36,代码来源:CCScene.cpp

示例2: ccTouchesBegan


//.........这里部分代码省略.........
        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;
        if (touchMode == kCCTouchesAllAtOnce)
        {
            node->ccTouchesBegan(pTouches, pEvent);
        }
        else
        {
            ret = node->ccTouchBegan(touchTarget->findTouch(pTouches), pEvent);
        }

        if (ret)
        {
            m_touchingTargets->addObject(touchTarget);
//            CCLOG("ADD TOUCH TARGET [%p]", touchTarget);
        }

        if (node->isTouchSwallowEnabled())
        {
            // target swallow touch event, stop dispatching
            break;
        }

        // continue dispatching, try to next
    }
开发者ID:Pythoner-xu,项目名称:quick-cocos2d-x,代码行数:101,代码来源:CCScene.cpp


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