Exemplo n.º 1
0
bool VVAlertViewForInput::initWithTitle(const char* aTitle, const char* aMessage, VVAlertViewDelegate* aDelegate, const char* aCancelBtnTitle, const char* aOtherBtnTitle, 
                                         const char* aPlaceHolder, VVTextFieldDelegate* aTextDelegate)
{
    if( !VVAlertView::initWithTitle(aTitle, aMessage, aDelegate, aCancelBtnTitle,aOtherBtnTitle, centerPadding) )
        return false;
    
    float txtBoxPaddingLeft = 10;
    float txtBoxPaddingTop = 5;
    CCScale9Sprite *txtbg = CCScale9Sprite::scale9SpriteWithFile(param.fieldBG_name.c_str(), param.field9patch_rect);
    if( txtbg )
    {
        txtbg->setContentSize(CCSizeMake(param.fieldSize.width+txtBoxPaddingLeft*2, param.fieldSize.height+txtBoxPaddingTop*2));
        txtbg->setAnchorPoint(ccp(0.5,0));
        txtbg->setPosition(ccp(0, centerOfMargin-txtBoxPaddingTop));
        addChild(txtbg);
    }
    
    txtField = new VVTextField();
    txtField->initWithPlaceHolder(aPlaceHolder, fontName.c_str(), param.textFieldFontSize, param.maxFieldLength, param.fieldSize);
    txtField->setPosition(ccp(-param.fieldSize.width/2,centerOfMargin));
    txtField->setDelegate(aTextDelegate);
//    txtField->setIsAcceptingOnlyASCII(true);
    
    addChild(txtField);
    txtField->release();
    
    return true;
}
Exemplo n.º 2
0
void CCAnimate9SpriteProgress::startWithTarget(CCNode* target)
{
    CCActionInterval::startWithTarget(target);
    
    CCScale9Sprite* sprite = (CCScale9Sprite*)target;
    beginSize = sprite->getContentSize();
}
Exemplo n.º 3
0
LFToast::LFToast(string msg,float during)
{
	CCSize visibleSize = CCDirector::sharedDirector()->getVisibleSize();
	CCScale9Sprite* base = CCScale9Sprite::create("toast.png");
	CCLabelTTF* lable = CCLabelTTF::create(
		msg.c_str(),
		fontStr_kaiti,
		30,
		CCSize(base->getContentSize().width - 10,0), 
		kCCTextAlignmentLeft);
	lable->setAnchorPoint(ccp(0,0.5f));
	addChild(base);
	base->setContentSize(CCSizeMake(base->getContentSize().width,lable->getContentSize().height + 20));
	base->setOpacity(0);
	base->addChild(lable);
	lable->setPosition(ccp(10,base->getContentSize().height/2));
	base->setPosition(ccp(visibleSize.width/2,base->getContentSize().height + 20));
	base->runAction(CCSequence::create(
		CCFadeTo::create(0.2f,255),
		CCDelayTime::create(during),
		CCFadeTo::create(0.1f,0),
		CCCallFuncN::create(this,SEL_CallFuncN(&LFToast::removeToast)),
		NULL
		));
}
CCMenuItemSprite * CCMenuItemDynamic::dynamicItemWithText(const char* text,  const char* font, const CCSize &minSize,  const char*normalImage, const char *selectedImage, CCObject* target, SEL_MenuHandler selector, const CCRect& centerRegion, GLubyte opacity) {
	  //Create the label
	  CCLabelBMFont *label = CCLabelBMFont ::labelWithString(text ,font);
	  label ->setOpacity(opacity);

	  //Calculate the Dynamic Button size
	  float minWidth = label->getContentSize().width>minSize.width?label->getContentSize().width:minSize.width;
	  float minHeight = label->getContentSize().height>minSize.height?label->getContentSize().height:minSize.height;

	  CCSize size(minWidth+30,minHeight+24);

	  label->setPosition(ccp(size.width*0.5f, size.height*0.5f));

	  //Sprite normal
	  CCScale9Sprite *normalSprite = CCScale9Sprite::scale9SpriteWithFile(normalImage, centerRegion);	
	  normalSprite ->setContentSize(size);
	  normalSprite ->setOpacity(opacity);
	  //Sprite selected
	  CCScale9Sprite *selectedSprite = NULL;
	  if(selectedImage){
		  selectedSprite = CCScale9Sprite::scale9SpriteWithFile(selectedImage, centerRegion);	
		  selectedSprite ->setContentSize(size);
		  selectedSprite->setOpacity(opacity);
	  }

	  //Create the CCMenuItemSprite
	  CCMenuItemSprite* returnItem = CCMenuItemSprite::itemFromNormalSprite(normalSprite,selectedSprite,target, selector);
	  returnItem->addChild(label);
	  return returnItem;

}
Exemplo n.º 5
0
void PopupLayer::onEnter(){
	CCLayer::onEnter();

	CCSize winSize = CCDirector::sharedDirector()->getWinSize();
	CCPoint pCenter = ccp(winSize.width / 2, winSize.height / 2);

	CCSize contentSize;
	if (getContentSize().equals(CCSizeZero)) {
		getSpriteBackGround()->setPosition(ccp(winSize.width / 2, winSize.height / 2));
		this->addChild(getSpriteBackGround(), 0, 0);
		contentSize = getSpriteBackGround()->getTexture()->getContentSize();
	} else {
		CCScale9Sprite *background = getSprite9BackGround();
		background->setContentSize(getContentSize());
		background->setPosition(ccp(winSize.width / 2, winSize.height / 2));
		this->addChild(background, 0, 0);
		contentSize = getContentSize();
	}

	this->addChild(getMenuButton());
	float btnWidth = contentSize.width / (getMenuButton()->getChildrenCount() + 1);

	CCArray* array = getMenuButton()->getChildren();
	CCObject* pObj = NULL;
	int i = 0;
	CCARRAY_FOREACH(array, pObj){
		CCNode* node = dynamic_cast<CCNode*>(pObj);
		node->setPosition(ccp( winSize.width / 2 - contentSize.width / 2 + btnWidth * (i + 1), winSize.height / 2 - contentSize.height / 3));
		i++;
	}
Exemplo n.º 6
0
CCScale9Sprite* TFBaseLayer::createTile(const char* spriteFrameName, CCSize size, CCPoint position)
{
    CCScale9Sprite* tile = CCScale9Sprite::createWithSpriteFrameName(spriteFrameName);
    tile->setPreferredSize(size);
    tile->setAnchorPoint(ccp(0.5f, 0.5f));
    tile->setPosition(position);
    
    return tile;
}
Exemplo n.º 7
0
void CAIndicator::setOpacity(GLubyte opacity)
{
    CCScale9Sprite* indicator = dynamic_cast<CCScale9Sprite*>(m_pIndicator);
    if (indicator)
    {
        indicator->setOpacity(opacity);
        indicator->setColor(ccc3(opacity, opacity, opacity));
    }
}
Exemplo n.º 8
0
LayerChanToast::LayerChanToast(string message){
	vector<string> lstRegex;
	for( int i = 1; i <= 16; i++ ){
		lstRegex.push_back( CCString::createWithFormat("(%d)", i)->getCString() );
	}

	this->setAnchorPoint(ccp(0, 0));
	// text
	cocos2d::ui::RichText* label = cocos2d::ui::RichText::create();
	label->setAnchorPoint(ccp(0, 0));
	label->setPosition(ccp(0, HEIGHT_DESIGN / 3.5));

	vector<string> lstContents = mUtils::splitStringByListRegex(message, lstRegex);
	int wLabel = 0, hLabel = 0;
	for( int i = 0; i < lstContents.size(); i++ ){
		bool check = false;
		int j = 0;
		for( j = 0; j < lstRegex.size(); j++ )
			if( lstRegex.at(j) == lstContents.at(i) ){
				check = true;
				break;
			}
			if( check ){
				CCArmature *armature = CCArmature::create(CCString::createWithFormat("onion%d", 1)->getCString());
				armature->getAnimation()->playByIndex(j);
				cocos2d::ui::RichElementCustomNode* recustom = cocos2d::ui::RichElementCustomNode::create(1, ccWHITE, 255, armature);
				label->pushBackElement(recustom);
				wLabel += 50;
				hLabel = 55;
			}else{
				CCLabelTTF *l = CCLabelTTF::create(lstContents.at(i).c_str(), "Arial", 16);
				l->setColor(ccc3(204, 16, 85));
				cocos2d::ui::RichElementText* re1 = cocos2d::ui::RichElementText::create(1, ccWHITE, 255, lstContents.at(i).c_str(), "Arial", 16);
				label->pushBackElement(re1);
				wLabel += l->getContentSize().width;
				hLabel = hLabel > 50 ? 55 : l->getContentSize().height;
			}
	}
	this->addChild(label, 1, 0);

	CCSize sizeDesign = CCSize(169, 30);
	CCSpriteBatchNode *batchNode = CCSpriteBatchNode::create("chats/framechat_a.png");
	CCScale9Sprite *blocks = CCScale9Sprite::create();
	blocks ->updateWithBatchNode(batchNode , CCRect(0, 0, sizeDesign.width, sizeDesign.height), false, CCRect(10, 10, sizeDesign.width - 20, sizeDesign.height - 20));

	CCSize size = CCSizeMake(wLabel + 10, hLabel + 5);
	blocks ->setContentSize(size);
	blocks->setAnchorPoint(ccp(0.5, 0.5));
	blocks->setPosition(ccp(label->getPositionX() + wLabel / 2, label->getPositionY() + hLabel / 2));

	blocks->setColor(ccc3(84, 81, 69));
	blocks->setOpacity(200);
	this->setPosition(ccp((WIDTH_DESIGN - size.width) / 2, 100));
	// add
	this->addChild(blocks);
}
Exemplo n.º 9
0
CCScale9Sprite* CCScale9Sprite::createWithSpriteFrame(CCSpriteFrame* spriteFrame, CCRect capInsets)
{
    CCScale9Sprite* pReturn = new CCScale9Sprite();
    if ( pReturn && pReturn->initWithSpriteFrame(spriteFrame, capInsets) )
    {
        CC_SAFE_AUTORELEASE(pReturn);
        return pReturn;
    }
    CC_SAFE_DELETE(pReturn);
    return NULL;
}
Exemplo n.º 10
0
CCScale9Sprite* CCScale9Sprite::createWithImage(CAImage* texture)
{
	CCScale9Sprite* pReturn = new CCScale9Sprite();
	if (pReturn && pReturn->initWithImage(texture))
	{
		pReturn->autorelease();
		return pReturn;
	}
	CC_SAFE_DELETE(pReturn);
	return NULL;
}
Exemplo n.º 11
0
CCScale9Sprite* CCScale9Sprite::createWithSpriteFrame(CCSpriteFrame* spriteFrame)
{
    CCScale9Sprite* pReturn = new CCScale9Sprite();
    if ( pReturn && pReturn->initWithSpriteFrame(spriteFrame) )
    {
        pReturn->autorelease();
        return pReturn;
    }
    CC_SAFE_DELETE(pReturn);
    return NULL;
}
Exemplo n.º 12
0
CCScale9Sprite* CCScale9Sprite::create(const char* file, CCRect rect)
{
    CCScale9Sprite* pReturn = new CCScale9Sprite();
    if ( pReturn && pReturn->initWithFile(file, rect) )
    {
        CC_SAFE_AUTORELEASE(pReturn);
        return pReturn;
    }
    CC_SAFE_DELETE(pReturn);
    return NULL;
}
Exemplo n.º 13
0
CCScale9Sprite* CCScale9Sprite::createWithSpriteFrameName(const char* spriteFrameName, CCRect capInsets)
{
    CCScale9Sprite* pReturn = new CCScale9Sprite();
    if ( pReturn && pReturn->initWithSpriteFrameName(spriteFrameName, capInsets) )
    {
        pReturn->autorelease();
        return pReturn;
    }
    CC_SAFE_DELETE(pReturn);
    return NULL;
}
Exemplo n.º 14
0
CCScale9Sprite* CCScale9Sprite::resizableSpriteWithCapInsets(CCRect capInsets)
{
    CCScale9Sprite* pReturn = new CCScale9Sprite();
    if ( pReturn && pReturn->initWithBatchNode(_scale9Image, m_spriteRect, capInsets) )
    {
        pReturn->autorelease();
        return pReturn;
    }
    CC_SAFE_DELETE(pReturn);
    return NULL;
}
Exemplo n.º 15
0
CCScale9Sprite* CCScale9Sprite::create(CCRect capInsets, const char* file)
{
    CCScale9Sprite* pReturn = new CCScale9Sprite();
    if ( pReturn && pReturn->initWithFile(capInsets, file) )
    {
        CC_SAFE_AUTORELEASE(pReturn);
        return pReturn;
    }
    CC_SAFE_DELETE(pReturn);
    return NULL;
}
Exemplo n.º 16
0
CCScale9Sprite* CCScale9Sprite::create()
{ 
    CCScale9Sprite *pReturn = new CCScale9Sprite();
    if (pReturn && pReturn->init())
    { 
        pReturn->autorelease();   
        return pReturn;
    } 
    CC_SAFE_DELETE(pReturn);
    return NULL;
}
Exemplo n.º 17
0
CCScale9Sprite* CCScale9Sprite::create(const char* file)
{
    CCScale9Sprite* pReturn = new CCScale9Sprite();
    if ( pReturn && pReturn->initWithFile(file) )
    {
        pReturn->autorelease();
        return pReturn;
    }
    CC_SAFE_DELETE(pReturn);
    return NULL;
}
Exemplo n.º 18
0
CCScale9Sprite* CCScale9Sprite::create()
{ 
    CCScale9Sprite *pReturn = new CCScale9Sprite();
    if (pReturn && pReturn->init())
    { 
        CC_SAFE_AUTORELEASE(pReturn);   
        return pReturn;
    } 
    CC_SAFE_DELETE(pReturn);
    return NULL;
}
Exemplo n.º 19
0
void BBProgressBar::updateProgress()
{

    float pv = (m_fCurrent - m_fMin) / (m_fMax - m_fMin);
    if(m_fMax - m_fMin == 0) pv=0;
    if(pv<0) pv=0;
    if(pv>1) pv=1;

    switch (m_nProgressBarMode)
    {
    case BB_PROGRESSBAR_MODE_SCALE:
    {
    }
    break;


    //基于9格缩放的进度条机制
    case BB_PROGRESSBAR_MODE_LAYOUT:
    {
        CCSize sizeLayout = m_pBackground->getContentSize();
        sizeLayout.width *= pv;

        CCScale9Sprite* pro = dynamic_cast<CCScale9Sprite*>(m_pProgress);
        if(pro)
        {
            pro->setPreferredSize(sizeLayout);

            if(m_bHideProgress) pro->setVisible(false);
            else if(pv>0.01) pro->setVisible(true);
            else pro->setVisible(false);
        }

        if(m_pLabel)
        {
            m_pLabel->setString(FORMAT("%d", (int)m_fCurrent));
        }
    }
    break;

    case BB_PROGRESSBAR_MODE_CIRCLE:
    {
        if(m_pPotentiometer)
        {
            m_pPotentiometer->setMaximumValue(m_fMax);
            m_pPotentiometer->setMinimumValue(m_fMin);
            m_pPotentiometer->setValue(m_fCurrent);
        }
    }
    break;
    }
};
Exemplo n.º 20
0
void PopCancelLayer::onEnter(){
	PopLayer::onEnter();
	CCMenuItemImage* cancelBtn = CCMenuItemImage::create("strangedesign/Dlg_cancel_button.png",
		"strangedesign/Dlg_cancel_button_down.png",
		this,
		menu_selector(PopCancelLayer::cancelCallback));
	CCScale9Sprite* background = getSprite9BackGround();
	CCPoint centerDlg = background->getPosition();
	CCSize backgroundSize = background->getContentSize();
	CCPoint rightCorner = centerDlg+ccp(backgroundSize.width/2, backgroundSize.height/2);
	CCSize cancelImgSize = cancelBtn->getContentSize();
	cancelBtn->setPosition(rightCorner-ccp(cancelImgSize.width/2,cancelImgSize.height/2));
	getMenuButton()->addChild(cancelBtn);
}
Exemplo n.º 21
0
	void setScrollBar(CCScale9Sprite *s){
		if(_scrollBar){ _scrollBar->removeAllChildrenWithCleanup(true);}
		_scrollBar = s;
		if(s){
			addChild(s, 255);
		}
	}
Exemplo n.º 22
0
	bool IrrPanel::init( const char* texture,IrrSize size,bool isPlist /*= false*/ )
	{
		CCScale9Sprite* pBackground = NULL;
		if(isPlist)
		{
			CCScale9Sprite* pBackground = CCScale9Sprite::createWithSpriteFrameName(texture);
		}
		else
		{
			CCScale9Sprite* pBackground = CCScale9Sprite::create(texture);
		}
		pBackground->setAnchorPoint(ccp(0,0));
		pBackground->setContentSize(CCSize(size.width,size.height));
		this->addChild(pBackground);
		return true;
	}
Exemplo n.º 23
0
	void setScrollTrack(CCScale9Sprite *st){
		if(_scrollTrack){ _scrollTrack->removeAllChildrenWithCleanup(true);}
		_scrollTrack = st;
		if(st){
			addChild(st, 254);
		}
	}
Exemplo n.º 24
0
void CCControlButton::setPreferredSize(CCSize size)
{
    if(size.width == 0 && size.height == 0)
    {
        m_doesAdjustBackgroundImage = true;
    }
    else
    {
        m_doesAdjustBackgroundImage = false;
        CCDictElement * item = NULL;
        CCDICT_FOREACH(m_backgroundSpriteDispatchTable, item)
        {
            CCScale9Sprite* sprite = (CCScale9Sprite*)item->getObject();
            sprite->setPreferredSize(size);
        }
    }
Exemplo n.º 25
0
CCScale9Sprite* CCScale9Sprite::createWithSpriteFrameName(const char* spriteFrameName)
{
    CCAssert(spriteFrameName != NULL, "spriteFrameName must be non-NULL");

    CCScale9Sprite* pReturn = new CCScale9Sprite();
    if ( pReturn && pReturn->initWithSpriteFrameName(spriteFrameName) )
    {
        pReturn->autorelease();
        return pReturn;
    }
    CC_SAFE_DELETE(pReturn);

    CCLog("Could not allocate CCScale9Sprite()");
    return NULL;
    
}
Exemplo n.º 26
0
void GameRankLayer::initTabs()
{
	// Friend Tab
	CCScale9Sprite* ptrTabFriendsSelected = GameUtils::createScale9("new_blue_bg.png",
		CCRectMake(0,0,200,82),CCRectMake(35,35,125,10));
	ptrTabFriendsSelected->setContentSize(CCSizeMake(204,82));
	CCScale9Sprite* ptrTabFriendsDisabled = GameUtils::createScale9("new_blue_bg.png",
		CCRectMake(0,0,200,82),CCRectMake(35,35,125,10));
	ptrTabFriendsDisabled->setContentSize(CCSizeMake(204,82));
	CCNode* ptrTabFriendsNormal = CCNode::create();
	ptrTabFriendsNormal->setContentSize(ptrTabFriendsSelected->getContentSize());

	m_ptrTabFriends = CCMenuItemSprite::create(ptrTabFriendsNormal, ptrTabFriendsSelected, 
		ptrTabFriendsDisabled, this, menu_selector(GameRankLayer::tabFriendsCallback));
	m_ptrBg->addChild(m_ptrTabFriends);
	LayoutUtil::layoutParentLeftTop(m_ptrTabFriends, -5, -27);
	registerMenuItem(m_ptrTabFriends);

	m_ptrLbFriends = CCLabelBMFont::create(LOCALIZED_STRING("word_friends"), 
		FontConstant::BMFONT_GOTHIC725_BLK_BT_BLUE);
	m_ptrLbFriends->setScale(0.6f);
	m_ptrTabFriends->addChild(m_ptrLbFriends);
	LayoutUtil::layoutParentBottom(m_ptrLbFriends,6,22);

	// Global Tab
	CCScale9Sprite* ptrTabGlobalSelected = GameUtils::createScale9("new_blue_bg.png",
		CCRectMake(0,0,200,82),CCRectMake(35,35,125,10));
	ptrTabGlobalSelected->setContentSize(CCSizeMake(204,82));
	CCScale9Sprite* ptrTabGlobalDisabled = GameUtils::createScale9("new_blue_bg.png",
		CCRectMake(0,0,200,82),CCRectMake(35,35,125,10));
	ptrTabGlobalDisabled->setContentSize(CCSizeMake(204,82));
	CCNode* ptrTabGlobalNormal = CCNode::create();
	ptrTabGlobalNormal->setContentSize(ptrTabGlobalSelected->getContentSize());
	m_ptrTabGolbal = CCMenuItemSprite::create(ptrTabGlobalNormal, ptrTabGlobalSelected,
		ptrTabGlobalDisabled,this, menu_selector(GameRankLayer::tabGlobalCallback));
	m_ptrBg->addChild(m_ptrTabGolbal);
	LayoutUtil::layoutRight(m_ptrTabGolbal,m_ptrTabFriends,-44);
	registerMenuItem(m_ptrTabGolbal);

	m_ptrLbGlobal = CCLabelBMFont::create(LOCALIZED_STRING("word_global"), 
		FontConstant::BMFONT_GOTHIC725_BLK_BT_BLUE);
	m_ptrLbGlobal->setScale(0.6f);
	m_ptrTabGolbal->addChild(m_ptrLbGlobal);
	LayoutUtil::layoutParentBottom(m_ptrLbGlobal,5,22);

	tabFriendsCallback(NULL);
}
Exemplo n.º 27
0
bool CCControlScene::init()
{
    if (CCLayer::init())
    {    
        // Get the sceensize
        CCSize screensize = CCDirector::sharedDirector()->getWinSize();

        CCMenuItemFont* pBackItem = CCMenuItemFont::create("Back", this,
            menu_selector(CCControlScene::toExtensionsMainLayer));
        pBackItem->setPosition(ccp(screensize.width - 50, 25));
        CCMenu* pBackMenu = CCMenu::create(pBackItem, NULL);
        pBackMenu->setPosition( CCPointZero );
        addChild(pBackMenu, 10);

        // Add the generated background
        CCSprite *background = CCSprite::create("extensions/background.png");
        background->setPosition(ccp(screensize.width / 2, screensize.height / 2));
        addChild(background);
        
        // Add the ribbon
        CCScale9Sprite *ribbon = CCScale9Sprite::create("extensions/ribbon.png", CCRectMake(1, 1, 48, 55));
        ribbon->setContentSize(CCSizeMake(screensize.width, 57));
        ribbon->setPosition(ccp(screensize.width / 2.0f, screensize.height - ribbon->getContentSize().height / 2.0f));
        addChild(ribbon);
        
        // Add the title
        setSceneTitleLabel(CCLabelTTF::create("Title", "Arial", 12));
        m_pSceneTitleLabel->setPosition(ccp (screensize.width / 2, screensize.height - m_pSceneTitleLabel->getContentSize().height / 2 - 5));
        addChild(m_pSceneTitleLabel, 1);
        
        // Add the menu
        CCMenuItemImage *item1 = CCMenuItemImage::create("Images/b1.png", "Images/b2.png", this, menu_selector(CCControlScene::previousCallback));
        CCMenuItemImage *item2 = CCMenuItemImage::create("Images/r1.png", "Images/r2.png", this, menu_selector(CCControlScene::restartCallback));
        CCMenuItemImage *item3 = CCMenuItemImage::create("Images/f1.png", "Images/f2.png", this, menu_selector(CCControlScene::nextCallback));
        
        CCMenu *menu = CCMenu::create(item1, item3, item2, NULL);
        menu->setPosition(CCPointZero);
        item1->setPosition(ccp(screensize.width / 2 - 100, 37));
        item2->setPosition(ccp(screensize.width / 2, 35));
        item3->setPosition(ccp(screensize.width / 2 + 100, 37));
        
        addChild(menu ,1);

        return true;
    }
    return false;
}
Exemplo n.º 28
0
void AchieveItemSprite::createChildren(AchieveManager::AchieveVO vo)
{
	CCSprite *p = CCSprite::create(g_sAchieveItemBGImage);
	CCSize ps = p->getContentSize();
	CCSize s = CCDirector::sharedDirector()->getWinSize();
	CCScale9Sprite* bg = CCScale9Sprite::create(g_sAchieveItemBGImage,CCRectMake(0,0,ps.width,ps.height),CCRectMake(20,20,ps.width-40,ps.height-40));
	this->addChild(bg);

	char url[64] = {0};
	sprintf(url,"%s%d%s", "./image/achieve/", vo.id, ".png");

	CCSprite* pic = CCSprite::create(url);
	this->addChild(pic);

	//this->setTouchEnabled(false);
	bg->setPreferredSize(CCSizeMake(350,120));
}
Exemplo n.º 29
0
bool CCControlButtonTest_HelloVariableSize::init()
{
    if (CCControlScene::init())
    {
        CCSize screenSize = CCDirector::sharedDirector()->getWinSize();
        
        // Defines an array of title to create buttons dynamically
        CCArray *stringArray = CCArray::create(
            ccs("Hello"),
            ccs("Variable"),
            ccs("Size"),
            ccs("!"),
            NULL);
        
        CCNode *layer = CCNode::create();
        addChild(layer, 1);
        
        double total_width = 0, height = 0;
        
        // For each title in the array
        CCObject* pObj = NULL;
        CCARRAY_FOREACH(stringArray, pObj)
        {
            CCString* title = (CCString*)pObj;
            // Creates a button with this string as title
            CCControlButton *button = standardButtonWithTitle(title->getCString());
            button->setPosition(ccp (total_width + button->getContentSize().width / 2, button->getContentSize().height / 2));
            layer->addChild(button);
            
            // Compute the size of the layer
            height = button->getContentSize().height;
            total_width += button->getContentSize().width;
        }

        layer->setAnchorPoint(ccp (0.5, 0.5));
        layer->setContentSize(CCSizeMake(total_width, height));
        layer->setPosition(ccp(screenSize.width / 2.0f, screenSize.height / 2.0f));
        
        // Add the black background
        CCScale9Sprite *background = CCScale9Sprite::create("extensions/buttonBackground.png");
        background->setContentSize(CCSizeMake(total_width + 14, height + 14));
        background->setPosition(ccp(screenSize.width / 2.0f, screenSize.height / 2.0f));
        addChild(background);
        return true;
    }
Exemplo n.º 30
0
void CCAnimate9SpriteProgress::update(float fraction)
{
    CCNode* target = getTarget();
    CCScale9Sprite* sprite = (CCScale9Sprite*)target;
    
    float width = beginSize.width + fraction * distance;

    if (capAtMax)
        width = std::min(width, maxWidth);
    else
        while (width - maxWidth > 1e-3) width -= maxWidth;
    
    if (width - minWidth < 1e-3)
        width = minWidth;
    
    sprite->setVisible(width > minWidth);
    sprite->setContentSize(CCSize(width, beginSize.height));
}