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


C++ CCClippingNode::getStencil方法代码示例

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


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

示例1: update

void CCClipOut::update(float time) {
    CCClippingNode* clipper = (CCClippingNode*)getTarget();
    CCDrawNode* stencil = (CCDrawNode*)clipper->getStencil();
    
    // clear
    stencil->clear();
    
    // build polygon
    float distance = m_distance * (1 - time);
    if(distance < FLT_EPSILON) {
        CCPoint v[] = {
            CCPointZero,
            CCPointZero,
            CCPointZero,
            CCPointZero
        };
        stencil->drawPolygon(v, 4, cc4fGREEN, 0, cc4fTRANSPARENT);
    } else {
        CCPoint v[] = {
            m_p1,
            m_p2,
            ccp(m_p2.x + distance * m_cos,
                m_p2.y + distance * m_sin),
            ccp(m_p1.x + distance * m_cos,
                m_p1.y + distance * m_sin)
        };
        stencil->drawPolygon(v, 4, cc4fGREEN, 0, cc4fTRANSPARENT);
    }
}
开发者ID:huaqiangs,项目名称:cocos2dx-common,代码行数:29,代码来源:CCClipOut.cpp

示例2: startWithTarget

void CCClipOut::startWithTarget(CCNode *pTarget) {
    CCAssert(dynamic_cast<CCClippingNode*>(pTarget) != NULL, "CCClipOut target must be a CCClippingNode instance");
    
    CCActionInterval::startWithTarget(pTarget);
    
    // ensure the stencil of clipper is CCDrawNode
    CCClippingNode* clipper = (CCClippingNode*)pTarget;
    CCNode* stencil = clipper->getStencil();
    if(dynamic_cast<CCDrawNode*>(stencil) == NULL) {
        clipper->setStencil(CCDrawNode::create());
    }
    
    // direction radian
    // treat is like a clip in
    float r = ccpToAngle(ccp(-m_direction.x, -m_direction.y));
    m_cos = cosf(r);
    m_sin = sinf(r);
    
    // max distance along direction
    const CCSize& size = pTarget->getContentSize();
    m_distance = size.width * fabsf(m_cos) + size.height * fabsf(m_sin);
    
    // calculate fixed edge endpoints
    if(r > M_PI_2) {
        float p1Len = size.width * cosf(r - M_PI_2);
        m_p1.x = size.width - p1Len * cosf(r - M_PI_2);
        m_p1.y = -p1Len * sinf(r - M_PI_2);
        float p2Len = size.height * sinf(r - M_PI_2);
        m_p2.x = size.width + p2Len * cosf(r - M_PI_2);
        m_p2.y = p2Len * sinf(r - M_PI_2);
    } else if(r >= 0) {
        float p1Len = size.height * m_cos;
        m_p1.x = p1Len * cosf(r + M_PI_2);
        m_p1.y = p1Len * sinf(r + M_PI_2);
        float p2Len = size.width * m_sin;
        m_p2.x = p2Len * cosf(r - M_PI_2);
        m_p2.y = p2Len * sinf(r - M_PI_2);
    } else if(r < -M_PI_2) {
        float p1Len = size.height * sinf(-r - M_PI_2);
        m_p1.x = size.width + p1Len * cosf(-r - M_PI_2);
        m_p1.y = size.height - p1Len * sinf(-r - M_PI_2);
        float p2Len = size.width * cosf(-r - M_PI_2);
        m_p2.x = size.width - p2Len * cosf(-r - M_PI_2);
        m_p2.y = size.height + p2Len * sinf(-r - M_PI_2);
    } else {
        float p1Len = size.width * sinf(-r);
        m_p1.x = p1Len * cosf(r + M_PI_2);
        m_p1.y = size.height + p1Len * sinf(r + M_PI_2);
        float p2Len = size.height * cosf(-r);
        m_p2.x = -p2Len * cosf(r + M_PI_2);
        m_p2.y = size.height - p2Len * sinf(r + M_PI_2);
    }
}
开发者ID:huaqiangs,项目名称:cocos2dx-common,代码行数:53,代码来源:CCClipOut.cpp

示例3: update

void CCClipIn::update(float time) {
    CCClippingNode* clipper = (CCClippingNode*)getTarget();
    CCDrawNode* stencil = (CCDrawNode*)clipper->getStencil();
    
    // clear
    stencil->clear();
    
    // build polygon
    float distance = m_distance * time;
    CCPoint v[] = {
        m_p1,
        m_p2,
        ccp(m_p2.x + distance * m_cos,
            m_p2.y + distance * m_sin),
        ccp(m_p1.x + distance * m_cos,
            m_p1.y + distance * m_sin)
    };
    stencil->drawPolygon(v, 4, cc4fGREEN, 0, cc4fTRANSPARENT);
}
开发者ID:aboduo,项目名称:cocos2dx-classical,代码行数:19,代码来源:CCClipIn.cpp


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