Ejemplo n.º 1
0
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;
    }

}
Ejemplo n.º 2
0
bool OptionLayer::init() {
    if (!CCLayer::init()) {
        return false;
    }

    _back = CCSprite::create("back.png");
    _back->setPosition(ccp(24 + 40, 800 - 56.5 + 15));
    this->addChild(_back);

    CCSprite * mode = CCSprite::create("mode.png");
    mode->setPosition(ccp(132 + 111, 800 - 103 - 19.5));
    this->addChild(mode);

    CCSpriteBatchNode* batchNode = CCSpriteBatchNode::create("dotted_line.png");
    int dottedLineY[3] = {313, 420, 539};
    for (int i = 0; i < 3; i++) {
        CCSprite * dotLine = CCSprite::createWithTexture(batchNode->getTexture());
        dotLine->setPosition(ccp(27 + 210.5, 800 - dottedLineY[i] - 1.5));
        this->addChild(dotLine);
    }

    _switchIndex = -1;
    _switches[0] = &Settings::showConflictedDigit;
    _switches[1] = &Settings::musicEnabled;
    _switches[2] = &Settings::soundEnabled;
    _switches[3] = &Settings::preventSleeping;
    _switches[4] = &Settings::showTimer;
    _switches[5] = &Settings::autoHighLight;
    _switches[6] = &Settings::autoRemoveNotes;
    _switches[7] = &Settings::removeCompleteDigits;

    CCSpriteBatchNode* maskBatchNode = CCSpriteBatchNode::create("mask.png");
    CCSpriteBatchNode* switchBatch = CCSpriteBatchNode::create("switch.png");
    _switchButtons = CCArray::createWithCapacity(7);
    _switchButtons->retain();
    char opLabel[10];
    int opLabelY[8] = {271, 332, 379, 445, 492, 566, 612, 657};
    for(int i = 0; i < 8; i++) {
        sprintf(opLabel, "op%d.png", i);
        CCSprite * label = CCSprite::create(opLabel);
        label->setPosition(ccp(25 + label->boundingBox().size.width / 2,
                               800 - opLabelY[i] - label->boundingBox().size.height / 2));
        this->addChild(label);

        CCSprite * stencil = CCSprite::createWithTexture(maskBatchNode->getTexture());
        stencil->setPosition(ccp(380 + 39, 800 - opLabelY[i] - label->boundingBox().size.height / 2));
        CCClippingNode * cliper = CCClippingNode::create(stencil);
        cliper->setAlphaThreshold(0);
        CCSprite * switchButton = CCSprite::createWithTexture(switchBatch->getTexture());
        switchButton->setPosition(ccp(*(_switches[i]) ? 394 + 49 : 394, 800 - opLabelY[i] - label->boundingBox().size.height / 2));
        _switchButtons->addObject(switchButton);
        cliper->addChild(switchButton);
        this->addChild(cliper);
    }

    this->setTouchEnabled(true);
    this->setKeypadEnabled(true);

    return true;
}
Ejemplo n.º 3
0
CCClippingNode* SpriteInvertedTest::clipper()
{
    CCClippingNode *clipper = SpriteTest::clipper();
    clipper->setAlphaThreshold(0.05f);
    clipper->setInverted(true);
    return clipper;
}
Ejemplo n.º 4
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.º 5
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.º 6
0
bool Recipe26::init()
{
    if ( !RecipeBase::init() )
    {
        return false;
    }

    CCSize size = CCDirector::sharedDirector()->getVisibleSize();

    CCSprite* pSprite = CCSprite::create("HelloWorld.png");
    pSprite->setPosition( ccp(size.width/2, size.height/2) );

    CCSprite* pMask = CCSprite::create("mask_star.png");
    pMask->setPosition(ccp(size.width/2, size.height/2));

    CCClippingNode* pClip = CCClippingNode::create();
    pClip->setStencil(pMask);
    pClip->setAlphaThreshold(0.0f);
    pClip->addChild(pSprite);

    this->addChild(pClip);

    return true;
}
Ejemplo n.º 7
0
CCClippingNode* SpriteNoAlphaTest::clipper()
{
    CCClippingNode *clipper = SpriteTest::clipper();
    clipper->setAlphaThreshold(1);
    return clipper;
}
Ejemplo n.º 8
0
CCClippingNode* SpriteTest::clipper()
{
    CCClippingNode *clipper = BasicTest::clipper();
    clipper->setAlphaThreshold(0.05f);
    return clipper;
}
Ejemplo n.º 9
0
void CCScrollBar::attachToUIScrollView(ScrollView* scrollView, ccInsets insets, bool horizontal) {
	// save flag
	m_horizontal = horizontal;
	
	// add to scroll view
	float thumbLength = 0;
	Widget* svParent = dynamic_cast<Widget*>(scrollView->getParent());
	CCSize svSize = scrollView->getSize();
	CCPoint svOrigin = CCUtils::getOrigin(scrollView);
	CCSize innerSize = scrollView->getInnerContainerSize();
	CCSize sbSize;
	if(horizontal) {
		sbSize = CCSizeMake(m_track->getContentSize().width,
							svSize.width - insets.left - insets.right);
		setContentSize(sbSize);
		setAnchorPoint(ccp(0, 0.5f));
		setPosition(ccp(svOrigin.x + svSize.width / 2,
						svOrigin.y + insets.bottom));
		setRotation(-90);
		svParent->addNode(this, MAX_INT);
		
		// thumb length
		if(m_fixedThumb)
			thumbLength = m_fixedThumb->getContentSize().height;
		else
			thumbLength = MIN(1, svSize.width / innerSize.width) * sbSize.height;
	} else {
		sbSize = CCSizeMake(m_track->getContentSize().width,
							svSize.height - insets.top - insets.bottom);
		setContentSize(sbSize);
		setAnchorPoint(ccp(1, 0.5f));
		setPosition(ccp(svOrigin.x + svSize.width - insets.right,
						svOrigin.y + svSize.height / 2));
		svParent->addNode(this, MAX_INT);
		
		// thumb length
		if(m_fixedThumb)
			thumbLength = m_fixedThumb->getContentSize().height;
		else
			thumbLength = MIN(1, svSize.height / innerSize.height) * sbSize.height;
	}
	
	// add track
	m_track->setPreferredSize(sbSize);
	m_track->setPosition(CCUtils::getLocalCenter(this));
	addChild(m_track);
	
	// clipping node to hold thumb
	CCClippingNode* thumbClipping = CCClippingNode::create(m_track);
	thumbClipping->ignoreAnchorPointForPosition(false);
	thumbClipping->setAnchorPoint(ccp(0.5f, 0.5f));
	thumbClipping->setContentSize(sbSize);
	thumbClipping->setPosition(CCUtils::getLocalCenter(this));
	thumbClipping->setAlphaThreshold(0.5f);
	thumbClipping->setScaleX((sbSize.width - 4) / sbSize.width);
	thumbClipping->setScaleY((sbSize.height - 4) / sbSize.height);
	addChild(thumbClipping);
	
	// thumb or fixed thumb
	if(m_thumb) {
		m_thumb->setPreferredSize(CCSizeMake(sbSize.width, thumbLength));
		m_thumb->setPosition(ccp(sbSize.width / 2,
								 sbSize.height - thumbLength / 2));
		thumbClipping->addChild(m_thumb);
	} else {
		m_fixedThumb->setPosition(ccp(sbSize.width / 2,
									  sbSize.height - thumbLength / 2));
		thumbClipping->addChild(m_fixedThumb);
	}
	
	// sync thumb position
	syncThumbPositionForUIScrollView(scrollView);
	
	// listen to scrollview scrolling event
	scrollView->addEventListenerScrollView(this, scrollvieweventselector(CCScrollBar::onUIScrollViewEvent));
    
    // init fade out
    if(m_initFadeOut) {
        m_fadingOut = true;
        CCUtils::setOpacityRecursively(this, 0);
    }
}
Ejemplo n.º 10
0
void CCScrollBar::attachToCCScrollView(CCScrollView* scrollView, ccInsets insets, bool horizontal) {
    // it must have parent node
    CCNode* svParent = scrollView->getParent();
    if(!svParent) {
        CCLOGWARN("CCScrollView must be added to one node before calling attachToCCScrollView");
        return;
    }
    
	// save flag
	m_horizontal = horizontal;
	
	// add to scroll view
	float thumbLength = 0;
    CCPoint svOrigin = CCUtils::getOrigin(scrollView);
	CCSize svSize = scrollView->getViewSize();
	CCSize innerSize = scrollView->getContainer()->getContentSize();
	CCSize sbSize;
	if(horizontal) {
		sbSize = CCSizeMake(m_track->getContentSize().width,
							svSize.width - insets.left - insets.right);
		setContentSize(sbSize);
		setAnchorPoint(ccp(0, 0.5f));
		setPosition(ccp(svOrigin.x + svSize.width / 2, svOrigin.y + insets.bottom));
		setRotation(-90);
        UIWidget* svpWidght = dynamic_cast<UIWidget*>(svParent);
        if(svpWidght)
            svpWidght->addNode(this, MAX_INT);
        else
            svParent->addChild(this, MAX_INT);
		
		// thumb length
		if(m_fixedThumb)
			thumbLength = m_fixedThumb->getContentSize().height;
		else
			thumbLength = MIN(1, svSize.width / innerSize.width) * sbSize.height;
	} else {
		sbSize = CCSizeMake(m_track->getContentSize().width,
							svSize.height - insets.top - insets.bottom);
		setContentSize(sbSize);
		setAnchorPoint(ccp(1, 0.5f));
		setPosition(ccp(svOrigin.x + svSize.width - insets.right, svOrigin.y + svSize.height / 2));
        UIWidget* svpWidght = dynamic_cast<UIWidget*>(svParent);
        if(svpWidght)
            svpWidght->addNode(this, MAX_INT);
        else
            svParent->addChild(this, MAX_INT);
		
		// thumb length
		if(m_fixedThumb)
			thumbLength = m_fixedThumb->getContentSize().height;
		else
			thumbLength = MIN(1, svSize.height / innerSize.height) * sbSize.height;
	}
	
	// add track
	m_track->setPreferredSize(sbSize);
	m_track->setPosition(CCUtils::getLocalCenter(this));
	addChild(m_track);
	
	// clipping node to hold thumb
	CCClippingNode* thumbClipping = CCClippingNode::create(m_track);
	thumbClipping->ignoreAnchorPointForPosition(false);
	thumbClipping->setAnchorPoint(ccp(0.5f, 0.5f));
	thumbClipping->setContentSize(sbSize);
	thumbClipping->setPosition(CCUtils::getLocalCenter(this));
	thumbClipping->setAlphaThreshold(0.5f);
	thumbClipping->setScaleX((sbSize.width - 4) / sbSize.width);
	thumbClipping->setScaleY((sbSize.height - 4) / sbSize.height);
	addChild(thumbClipping);
	
	// thumb or fixed thumb
	if(m_thumb) {
		m_thumb->setPreferredSize(CCSizeMake(sbSize.width, thumbLength));
		m_thumb->setPosition(ccp(sbSize.width / 2,
								 sbSize.height - thumbLength / 2));
		thumbClipping->addChild(m_thumb);
	} else {
		m_fixedThumb->setPosition(ccp(sbSize.width / 2,
									  sbSize.height - thumbLength / 2));
		thumbClipping->addChild(m_fixedThumb);
	}
	
	// sync thumb position
	syncThumbPositionForCCScrollView(scrollView);
    
    // delegate
    m_oldCCDelegate = scrollView->getDelegate();
    scrollView->setDelegate(this);
    
    // init fade out
    if(m_initFadeOut) {
        m_fadingOut = true;
        CCUtils::setOpacityRecursively(this, 0);
    }
}
Ejemplo n.º 11
0
bool Recipe26::init()
{
    if ( !RecipeBase::init() )
    {
        return false;
    }
    
    
    CCLayerColor* panelBg = CCLayerColor::create(ccc4(51, 51, 51, 255),640,1150);
    panelBg->setPosition(ccp(0,0));
    this->addChild(panelBg);
    
    targetLayer = CCLayer::create();
    this->addChild(targetLayer);
    
    // 画面の幅を取得
    CCSize winSize = CCDirector::sharedDirector()->getWinSize();
    // 画像ファイルとrectを指定してスプライトを作成
    CCSprite *player = CCSprite::create("image/quest/shuriken_m_avatar_skillpg_18.png", CCRectMake(0, 0, 100, 100) );
    // スプライトの位置を設定
    player->setPosition(ccp(player->getContentSize().width*3/2, winSize.height/2));
    // 後で識別できるようにタグを設定
    player->setTag(1);
    // スプライトをレイヤに追加
    targetLayer->addChild(player);
    
    CCSize visibleSize = CCDirector::sharedDirector()->getVisibleSize();
    
    TapSprite* sprite = (TapSprite*)TapSprite::create("image/quest/shuriken_m_avatar_skillpg_18.png");
    sprite->setPosition(ccp(visibleSize.width/2, visibleSize.height/2));
    sprite->setTag(2);
    targetLayer->addChild(sprite);
    
    
    // クリック用のボタン
    CCMenuItemImage *pCloseItem = CCMenuItemImage::create(
                                                          "image/ui/common_ui_mainButton_up.png",
                                                          "image/ui/common_ui_mainButton_down.png",
                                                          this,
                                                          menu_selector(Recipe26::testBtn1Handler));
    
    // 表示位置を指定
    pCloseItem->setPosition(ccp(winSize.width - pCloseItem->getContentSize().width / 2 ,
                                pCloseItem->getContentSize().height / 2));
    // CCMenuItemImage から CCMenuを作成
    CCMenu* pMenu = CCMenu::create(pCloseItem, NULL);
    // CCMenuとしての位置は(0,0)を指定
    pMenu->setPosition(-150,130);
    
    this->addChild(pMenu);
    
    
    //---------------------------
    CCSize size = CCDirector::sharedDirector()->getVisibleSize();
    
    CCSprite* pSprite = CCSprite::create("image/gacha/2204401.jpg");
    pSprite->setPosition( ccp(size.width/2, size.height/2) );
    
    CCSprite* pMask = CCSprite::create("image/quest/mask_star.png");
    pMask->setPosition(ccp(size.width/2, size.height/2));
    
    CCClippingNode* pClip = CCClippingNode::create();
    pClip->setStencil(pMask);
    pClip->setAlphaThreshold(0.05f);
    pClip->addChild(pSprite);
    targetLayer->addChild(pClip);
    
    CCMoveTo *actionMove = CCMoveTo::create(1.7f, ccp(200, 500));
    pClip->runAction(CCEaseExponentialInOut::create(actionMove));
    
    
    
    
    //---------------------------
    // 配列のテスト
    //---------------------------
    
    int arrN[] = {5,6,9,4};
    int iSize = sizeof(arrN) / sizeof(arrN[0]);
    
    for ( int i = 0 ; i < iSize ; i++ ) {
        CCLOG("ffgff : %i" , arrN[i]);
    }
    
    
    return true;
}