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


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

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


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

示例1: setup

void NestedTest::setup()
{
    static int depth = 9;
    
    CCNode *parent = this;
    
    for (int i = 0; i < depth; i++) {
                
        int size = 225 - i * (225 / (depth * 2));

        CCClippingNode *clipper = CCClippingNode::create();
        clipper->setContentSize(CCSizeMake(size, size));
        clipper->setAnchorPoint(ccp(0.5, 0.5));
        clipper->setPosition( ccp(parent->getContentSize().width / 2, parent->getContentSize().height / 2) );
        clipper->setAlphaThreshold(0.05f);
        clipper->runAction(CCRepeatForever::create(CCRotateBy::create(i % 3 ? 1.33 : 1.66, i % 2 ? 90 : -90)));
        parent->addChild(clipper);
        
        CCNode *stencil = CCSprite::create(s_pPathGrossini);
        stencil->setScale( 2.5 - (i * (2.5 / depth)) );
        stencil->setAnchorPoint( ccp(0.5, 0.5) );
        stencil->setPosition( ccp(clipper->getContentSize().width / 2, clipper->getContentSize().height / 2) );
        stencil->setVisible(false);
        stencil->runAction(CCSequence::createWithTwoActions(CCDelayTime::create(i), CCShow::create()));
        clipper->setStencil(stencil);

        clipper->addChild(stencil);
        
        parent = clipper;
    }

}
开发者ID:1901,项目名称:cocos2d-x,代码行数:32,代码来源:ClippingNodeTest.cpp

示例2: init

bool ImageEditLayer::init(){
    if (DialogLayer::init()) {
        
        
        this->setTitle("头像编辑");
        
        CCPoint middle=ccp(286, 154);
        CCSize size=CCSizeMake(570,300);
        
        CCClippingNode* clippingNode = CCClippingNode::create();
        //设置裁剪区域大小
        clippingNode->setContentSize(size);
        clippingNode->setAnchorPoint(ccp(0.5, 0.5));
        clippingNode->setPosition(middle);
        m_contentLayer->addChild(clippingNode);
        
        CCTexture2D* textrue=new CCTexture2D();
        textrue->autorelease();
        textrue->initWithImage(_image);
        _sprite=CCSprite::createWithTexture(textrue);
        _initPoint=ccp(clippingNode->getContentSize().width/2, clippingNode->getContentSize().height/2);
        _sprite->setPosition(_initPoint);
        
        CCSize spriteSize=_sprite->getContentSize();
        if (size.width/spriteSize.width<size.height/spriteSize.height) {
            _scale=size.width/spriteSize.width;
        }else{
            _scale=size.height/spriteSize.height;
        }
        
        _sprite->setScale(_scale);
        clippingNode->addChild(_sprite);
        
        //创建裁剪模板,裁剪节点将按照这个模板来裁剪区域
        CCDrawNode *stencil = CCDrawNode::create();
        CCPoint rectangle[4];
        rectangle[0] = ccp(0, 0);
        rectangle[1] = ccp(clippingNode->getContentSize().width, 0);
        rectangle[2] = ccp(clippingNode->getContentSize().width, clippingNode->getContentSize().height);
        rectangle[3] = ccp(0, clippingNode->getContentSize().height);
        
        ccColor4F white = {1, 1, 1, 1};
        //画一个多边形 这画一个200x200的矩形作为模板
        stencil->drawPolygon(rectangle, 4, white, 1, white);
        clippingNode->setStencil(stencil);
        
        //用来设置显示裁剪区域还是非裁剪区域的
        clippingNode->setInverted(false);//在裁剪区域内显示加入的内容
        
        _clip=CCClippingNode::create();//创建裁剪节点,成员变量
        _clip->setInverted(true);//设置底板可见
        _clip->setAlphaThreshold(0.0f);//设置alpha为0
        m_contentLayer->addChild(_clip);//添加裁剪节点
        
        _mask=CCLayerColor::create(ccc4(0,0,0,160),size.width,size.height);
        CCPoint point=ccp(middle.x-size.width/2,middle.y-size.height/2);
        _mask->setPosition(point);
        _clip->addChild(_mask);//为裁剪节点添加一个黑色带透明(看起了是灰色)的底板
        
        _stencil=CCSprite::create("default_avatar.png");//使用头像原图作为模板
        _stencil->setPosition(middle);
        _stencil->setScale(STENCIL_SCALE);
        _clip->setStencil(_stencil);//设置模版
        
        CCSprite* queding=CCSprite::createWithSpriteFrameName("touxiang_queding.png");
        CCMenuItemSprite* item=CCMenuItemSprite::create(queding, queding, this, menu_selector(ImageEditLayer::menuCallback));
        item->setPosition(ccp(290,-30));//注意contentlayer坐标原点位置
        item->setScale(0.7);
        item->setTag(kTagConfirm);
        this->addMenuItem(item,true);
        
        CCSprite* fanhui=CCSprite::createWithSpriteFrameName("touxiang_fanhui.png");
        fanhui->setScale(0.87);
        CCMenuItemSprite* fanhuiItem=CCMenuItemSprite::create(fanhui, fanhui, this, menu_selector(ImageEditLayer::menuCallback));
        fanhuiItem->setPosition(ccp(19,368));
        fanhuiItem->setTag(kTagBack);
        this->addMenuItem(fanhuiItem,true);
        
        CCPoint contentPoint=m_contentLayer->getPosition();
        _rect=CCRectMake(contentPoint.x+point.x, contentPoint.y+point.y, size.width,size.height);
        
        return true;
    }
    return false;
}
开发者ID:echenonline,项目名称:Blackcat,代码行数:85,代码来源:ImageEditLayer.cpp


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