Ejemplo n.º 1
0
bool Background::Init()
{
    do
    {
        CCNodeLoaderLibrary * ccNodeLoaderLibraryLeft = CCNodeLoaderLibrary::newDefaultCCNodeLoaderLibrary();
        CCBReader * ccbReaderLeft = new CCBReader(ccNodeLoaderLibraryLeft);
        CCNode * bgLeft = ccbReaderLeft->readNodeGraphFromFile("ccb/background.ccbi", this);
        CCBAnimationManager* animationManagerLeft = ccbReaderLeft->getAnimationManager();
        animationManagerLeft->runAnimationsForSequenceNamed("left");
        ccbReaderLeft->release();
        
        CCNodeLoaderLibrary * ccNodeLoaderLibraryRight = CCNodeLoaderLibrary::newDefaultCCNodeLoaderLibrary();
        CCBReader * ccbReaderRight = new CCBReader(ccNodeLoaderLibraryRight);
        CCNode * bgRight = ccbReaderRight->readNodeGraphFromFile("ccb/background.ccbi", this);
        CCBAnimationManager* animationManagerRight = ccbReaderRight->getAnimationManager();
        animationManagerRight->runAnimationsForSequenceNamed("right");
        ccbReaderRight->release();
        
        CCClippingNode * clippingNodeLeft = CCClippingNode::create();
        addChild(clippingNodeLeft);
        clippingNodeLeft->addChild(bgLeft,enZOrderBack,enTagBgLeft);
        CCDrawNode *shapeLeft = CCDrawNode::create();
        static CCPoint triangleLeft[3];
        triangleLeft[0] = ccp(0, 0);
        triangleLeft[1] = ccp(SCREEN_WIDTH,0);
        triangleLeft[2] = ccp(0,SCREEN_HEIGHT);
        static ccColor4F green = {0, 1, 0, 1};
        shapeLeft->drawPolygon(triangleLeft, 3, green, 0, green);
        clippingNodeLeft->setStencil(shapeLeft);
        clippingNodeLeft->setInverted(false);
        
        CCClippingNode * clippingNodeRight = CCClippingNode::create();
        addChild(clippingNodeRight);
        clippingNodeRight->addChild(bgRight,enZOrderBack,enTagBgRight);
        CCDrawNode *shapeRight = CCDrawNode::create();
        static CCPoint triangleRight[3];
        triangleRight[0] = ccp(SCREEN_WIDTH, SCREEN_HEIGHT);
        triangleRight[1] = ccp(SCREEN_WIDTH,0);
        triangleRight[2] = ccp(0,SCREEN_HEIGHT);
//        static ccColor4F green = {0, 1, 0, 1};
        shapeRight->drawPolygon(triangleRight, 3, green, 0, green);
        clippingNodeRight->setStencil(shapeRight);
        clippingNodeRight->setInverted(false);
        
        m_CraterArrayLeft = CCArray::create();
        m_CraterArrayLeft->retain();
        m_CraterArrayRight = CCArray::create();
        m_CraterArrayRight->retain();
        m_CraterArrayLeftDeleted = CCArray::create();
        m_CraterArrayLeftDeleted->retain();
        m_CraterArrayRightDeleted = CCArray::create();
        m_CraterArrayRightDeleted->retain();
        
        
        return true;
    } while (false);
    CCLog("Function Background::Init Error!");
    return false;
}
Ejemplo n.º 2
0
CCClippingNode* SpriteInvertedTest::clipper()
{
    CCClippingNode *clipper = SpriteTest::clipper();
    clipper->setAlphaThreshold(0.05f);
    clipper->setInverted(true);
    return clipper;
}
Ejemplo n.º 3
0
bool UIMakeProgress::initData(const char* fileName, const char* actionName)
{
    //init game Data
    //元素遮罩
    CCSprite* maskSprite = CCSprite::createWithSpriteFrameName(fileName);
    m_progressSprite = CCSprite::createWithSpriteFrameName(fileName);
    
    //血条开始位置和最后位置
    m_spriteStartPos = maskSprite->getPositionX() - maskSprite->getContentSize().width/2;
    m_spriteEndPos = maskSprite->getPositionX() + maskSprite->getContentSize().width/2;
    
    //血量上的动作
    CCSprite* m_actionSprite = CCSprite::createWithSpriteFrameName(actionName);
    
    m_actionSprite->setPosition(ccp(m_progressSprite->getContentSize().width/2, m_progressSprite->getContentSize().height/2));
    m_actionSprite->setColor(ccc3(108, 249, 206));
    m_actionSprite->setOpacity(0);
    m_actionSprite->setTag(0);
    
    m_progressSprite->addChild(m_actionSprite);
//    this->addChild(m_progressSprite);
    
    CCClippingNode* clip =CCClippingNode::create();
    
    //设定遮罩层
    clip->setStencil(maskSprite);
    
    //设定被遮罩层
    clip->addChild(m_progressSprite);
    //将ClippingNode放置到舞台显示
    this->addChild(clip);
    
    //设定遮罩图层的透明度取值范围
    clip->setAlphaThreshold(0);
    //设定遮罩的模式true显示没有被遮起来的纹理
    //如果是false就显示遮罩起来的纹理
    //clip是一个显示对象(容器)
    clip->setInverted(false);
    
    
    return true;
}
Ejemplo n.º 4
0
void HoleDemo::setup()
{
    CCSprite *target = CCSprite::create(s_pPathBlock);
    target->setAnchorPoint(CCPointZero);
    target->setScale(3);
    
    m_pOuterClipper = CCClippingNode::create();
    m_pOuterClipper->retain();
    CCAffineTransform tranform = CCAffineTransformMakeIdentity();
    tranform = CCAffineTransformScale(tranform, target->getScale(), target->getScale());

    m_pOuterClipper->setContentSize( CCSizeApplyAffineTransform(target->getContentSize(), tranform));
    m_pOuterClipper->setAnchorPoint( ccp(0.5, 0.5) );
    m_pOuterClipper->setPosition( ccpMult(ccpFromSize(this->getContentSize()), 0.5f) );
    m_pOuterClipper->runAction(CCRepeatForever::create(CCRotateBy::create(1, 45)));
    
    m_pOuterClipper->setStencil( target );
    
    CCClippingNode *holesClipper = CCClippingNode::create();
    holesClipper->setInverted(true);
    holesClipper->setAlphaThreshold( 0.05f );
    
    holesClipper->addChild(target);
    
    m_pHoles = CCNode::create();
    m_pHoles->retain();
    
    holesClipper->addChild(m_pHoles);
    
    m_pHolesStencil = CCNode::create();
    m_pHolesStencil->retain();
    
    holesClipper->setStencil( m_pHolesStencil);
    
    m_pOuterClipper->addChild(holesClipper);
    
    this->addChild(m_pOuterClipper);
        
    this->setTouchEnabled(true);
}
Ejemplo n.º 5
0
CCClippingNode* ShapeInvertedTest::clipper()
{
    CCClippingNode *clipper = ShapeTest::clipper();
    clipper->setInverted(true);
    return clipper;
}
Ejemplo n.º 6
0
bool TipsScene::init()
{
    if ( !CCLayer::init())
    {
        return false;
    }
    
    CCSize visibleSize = CCDirector::sharedDirector()->getVisibleSize();
    CCPoint origin = CCDirector::sharedDirector()->getVisibleOrigin();
	mCallFunc = NULL;
	targetRidus = 100;
	
	//创建一个遮罩层。
	CCLayerColor* pLayer;

	if (isHasTarget && !istouchRemove)
	{
		pLayer=CCLayerColor::create(ccc4(0,0,0,200));

		/*创建剪裁节点*/
		CCClippingNode* pClip = CCClippingNode::create() ;
		pClip->setInverted(true) ;//设置是否反向,将决定画出来的区域是透明的还是黑色的。
		this->addChild(pClip) ;
		/*注意将LayerColor层添加到剪裁节点上*/
		pClip->addChild(pLayer) ;

		//模板
		CCDrawNode* pStencil = CCDrawNode::create() ;
		static ccColor4F red = {1,0,0,1} ;


		float radius = targetRidus/2 ;
		const int nCount = 200 ;
		const float angel = 2.0 * (float)M_PI/nCount ;
		static CCPoint circle[nCount] ;
		for (int i=0; i<nCount; i++) {
			float radian = i*angel ;  //弧度
			circle[i].x = radius * cosf(radian) ;
			circle[i].y = radius * sinf(radian) ;
		}

		pStencil->drawPolygon(circle, nCount, red, 0, red) ;
		pStencil->runAction(CCRepeatForever::create(CCSequence::createWithTwoActions(CCScaleBy::create(0.2f, 0.9f), CCScaleTo::create(0.2f, 1)))) ;

		pStencil->setPosition(targetPoint);
		pClip->setStencil(pStencil) ;  //将这个区域从剪裁节点上面抠出来。Stencil是模板的意思
	}
	else if (shouldPauseGame)
	{
		pLayer=CCLayerColor::create(ccc4(0,0,0,100));
		this->addChild(pLayer) ;
	}
	else
	{
	}

	if (isAutoRemove)
	{
		scheduleOnce(schedule_selector(TipsScene::scheduleResumeGame),2.8);
		scheduleOnce(schedule_selector(TipsScene::scheduleRemove),3.0f);
	}
	
	CCSprite* tipsbg = CCSprite::create("tipbg.png");
	//tipsbg -> setPosition(ccp(375,260));
	tipsbg -> setPosition(ccp(375,260 + 160));
	addChild(tipsbg);

	mTipsWord = CCLabelTTF::create("","Arial",20);
	mTipsWord -> setColor(ccYELLOW);
	//mTipsWord -> setPosition(ccp(400,240));
	mTipsWord -> setPosition(ccp(400,240 + 160));
	addChild(mTipsWord);
	setTouchEnabled(true);

	if (shouldPauseGame)
	{
		BattleManage* pauseLayer = BattleManage::oneself;
		pauseLayer -> pauseSchedulerAndActions();
	}

    return true;
}
Ejemplo n.º 7
0
bool MainScene::Init()
{
    CCSize visibleSize = CCDirector::sharedDirector()->getVisibleSize();
    CCPoint origin = CCDirector::sharedDirector()->getVisibleOrigin();

    CCMenuItemImage *pCloseItem = CCMenuItemImage::create(
                                        "CloseNormal.png",
                                        "CloseSelected.png",
                                        this,
                                        menu_selector(MainScene::menuCloseCallback));
    
	pCloseItem->setPosition(ccp(origin.x + visibleSize.width - pCloseItem->getContentSize().width/2 ,
                                origin.y + pCloseItem->getContentSize().height/2));
    CCMenu* pMenu = CCMenu::create(pCloseItem, NULL);
    pMenu->setPosition(CCPointZero);
    this->addChild(pMenu, 1);

    CCLabelTTF* pLabel = CCLabelTTF::create("Hello World", "Arial", 24);
    pLabel->setPosition(ccp(origin.x + visibleSize.width/2,
                            origin.y + visibleSize.height - pLabel->getContentSize().height));
    this->addChild(pLabel, 1,1);

    CCSprite* pSprite = CCSprite::create("HelloWorld.png");
    pSprite->setPosition(ccp(visibleSize.width/2 + origin.x, visibleSize.height/2 + origin.y));
    this->addChild(pSprite, 0);
    
    setTouchEnabled(true);
    
//    /* Create an autorelease CCNodeLoaderLibrary. */
//    CCNodeLoaderLibrary * ccNodeLoaderLibrary = CCNodeLoaderLibrary::newDefaultCCNodeLoaderLibrary();
////    ccNodeLoaderLibrary->registerCCNodeLoader("MainScene", MainSceneLayerLoader::loader());
//    /* Create an autorelease CCBReader. */
//    cocos2d::extension::CCBReader * ccbReader = new cocos2d::extension::CCBReader(ccNodeLoaderLibrary);
//    /* Read a ccbi file. */
//    CCNode * node = ccbReader->readNodeGraphFromFile("MainScene.ccbi", this);
//    m_AnimationManager = ccbReader->getAnimationManager();
//    m_AnimationManager->runAnimationsForSequenceNamed("default");
//    m_bMenuShow = true;
//    ccbReader->release();
//    if(node != NULL) {
//        this->addChild(node);
//    }
    
//    CCFilteredSpriteWithOne* pSpOne = CCFilteredSpriteWithOne::create("Icon-144.png");
//    addChild(pSpOne);
//    pSpOne->setPosition(ccp(visibleSize.width/2,visibleSize.height/2));
//    CCGrayFilter* pF = CCGrayFilter::create(ccc4f(0.2, 0.3, 0.5, 0.1));
//    pSpOne->setFilter(pF);
//
//    CCFilteredSpriteWithMulti* pSpMulti = CCFilteredSpriteWithMulti::create("Icon-144.png");
//    addChild(pSpMulti);
//    pSpMulti->setPosition(ccp(visibleSize.width/2,visibleSize.height/4));
//    CCHueFilter* pF1 = CCHueFilter::create(240);
//    CCSaturationFilter* pF2 = CCSaturationFilter::create(1.5);
//    CCBrightnessFilter* pF3 = CCBrightnessFilter::create(-0.4);
//    CCArray* pArray = CCArray::create();
//    pArray->addObject(pF1);
//    pArray->addObject(pF2);
//    pArray->addObject(pF3);
//    pSpMulti->setFilters(pArray);
    
//    //test setBlendFunc
//    ccBlendFunc cbl = { GL_SRC_ALPHA , GL_ONE };
//    CCRotateBy * ccRotateBy = CCRotateBy::create(20.0f, 360);
//    CCRepeatForever * ccRepeatForever = CCRepeatForever::create(ccRotateBy);
//    this->mBurstSprite->runAction(ccRepeatForever);
//    pSp->setBlendFunc(cbl);
    
    //test Shader Utils
//    ShaderUtils::alphaMask(pSp, "Icon-114.png");
//    ShaderUtils::colorHSL(pSp, 120, 60);
    
    m_count = 0;
    
//    CCSprite *sprite = CCSprite::create("Icon-144.png");
//    CCSize winSize = CCDirector::sharedDirector()->getWinSize();
//    CCTableView* tableView = CCTableView::create(this,ccp(sprite->getContentSize().width*4,sprite->getContentSize().height*4));
//    tableView->setDirection(kCCScrollViewDirectionVertical);
//    tableView->setPosition(ccp(winSize.width/3,winSize.height/3));
//    tableView->setDelegate(this);
//    tableView->setVerticalFillOrder(kCCTableViewFillTopDown);
//    this->addChild(tableView,0,111);
//    tableView->reloadData();
//    sprite->release();
    
    //背景图片
    CCSprite * background = CCSprite::create("HelloWorld.png");
    background->setPosition(ccp(visibleSize.width/2,visibleSize.height/2));
    this->addChild(background,0);
    //创建一个裁剪节点用来实现遮罩的效果
    CCClippingNode * clippingNode = CCClippingNode::create();
    this->addChild(clippingNode,1);
    //向裁剪节点中加入内容,这里加入的是一个透明的层
    CCLayerColor * layer = CCLayerColor::create(ccc4(0,0,0,200));
    clippingNode->addChild(layer);
    //继续向裁剪节点中加入内容,这里加入的是一个精灵
    CCSprite * sprite = CCSprite::create("Icon-144.png");
    sprite->setPosition(ccp(visibleSize.width/4,visibleSize.height/2));
    clippingNode->addChild(sprite);
    //创建模板,裁剪节点将按照这个模板来裁剪区域
    CCSprite * stencil = CCSprite::create("Icon-114.png");
    stencil->setPosition(ccp(visibleSize.width/2,visibleSize.height/2));
    clippingNode->setStencil(stencil);
    //向裁剪节点中加入精灵,精灵的位置和裁剪的位置相同,所以最后让裁剪掉了
    CCSprite * sprite2 = CCSprite::create("Icon-144.png");
    sprite2->setPosition(ccp(visibleSize.width/2,visibleSize.height/2));
    clippingNode->addChild(sprite2);
    //这个是用来设置显示裁剪区域还是非裁剪区域的
    clippingNode->setInverted(true);
    //我们之前放了一张裁剪的模板,按照这个模板裁剪的时候同时按照这个alpha的值裁剪,这个值的范围是0-1
    //设为0就把透明的区域裁剪掉了
//    clippingNode->setAlphaThreshold(0);
    
    return true;
}
Ejemplo n.º 8
0
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;
}