bool GameSprite_Rice::init()
{
    if (!CCSprite::init()) {
        return false;
    }
    this->setContentSize(CCSize(500, 70));
    addRiceTime = RICEADDTIME;
    riceNum = 0;
    nowTime = 0;
    nowTime = this->getCurrentTime();
    //字体背景.
    CCMenuItemImage *labelBgSprite = CCMenuItemImage::create();
    labelBgSprite->setNormalSpriteFrame(GameShare_Texture::sharedTexture()->GetSpriteFrameByCCRect(akoomenu_image, CCRect(1763, 255, 120, 49)));
    labelBgSprite->setAnchorPoint(CCPointZero);
    labelBgSprite->setPosition(CCPointZero);
    labelBgSprite->setTag(Key_Add);
    CCMenu* pMenu = CCMenu::create(labelBgSprite, NULL);
    pMenu->setPosition(ccp(300,0));
    pMenu->setTag(Key_Add);
    this->addChild(pMenu);
    
    //时间标签.
    CCLabelTTF *timeLabel = CCLabelTTF::create("", "Arial", 20);
    ccColor3B color = ccc3(95, 46, 33);
    char strTime[32];
    sprintf(strTime,"%d:%d%d",addRiceTime/60,addRiceTime%60/10,addRiceTime%60%10);
    timeLabel->setColor(color);
    timeLabel->setString(strTime);
    timeLabel->setTag(Key_Time);
    timeLabel->setPosition(ccp(pMenu->getPositionX()+40, pMenu->getPositionY()+20));
    this->addChild(timeLabel);
    //饭的背景
    CCSprite *riceBgSprite = GameShare_Texture::sharedTexture()->GetSpriteByCCRect(akoomenu_image, CCRect(1, 1570, 278, 30));
    riceBgSprite->setAnchorPoint(CCPointZero);
    riceBgSprite->setPosition(ccp(0,5));
    this->addChild(riceBgSprite);
    
    this->schedule(schedule_selector(GameSprite_Rice::timeUpdate), 1.0);
    return true;
}
Ejemplo n.º 2
0
void ChallengeAgainLayer::onShow(int round, int need)
{
	float totalWidth = 0.0;
	CCSize s = CCDirector::sharedDirector()->getWinSize();
	CCSprite *app1 = CCSprite::create(g_sRelifeBGImage);
	app1->setAnchorPoint(ccp(0,0));
	app1->setPositionX(30);
	app1->setPositionY(s.height*0.5);
	this->addChild(app1);
	totalWidth += app1->getContentSize().width;

	NumberSprite * roundTip = NumberSprite::create("green60",round);
	roundTip->setAnchorPoint(ccp(0,0));
	roundTip->setPositionX(app1->getPositionX()+app1->getContentSize().width+4);
	roundTip->setPositionY(app1->getPositionY());
	this->addChild(roundTip);
	totalWidth += 4;
	totalWidth += roundTip->realWidth;

	CCSprite *app2 = CCSprite::create(g_sGuanBGImage);
	app2->setAnchorPoint(ccp(0,0));
	app2->setPositionX(roundTip->getPositionX()+roundTip->realWidth+4);
	app2->setPositionY(roundTip->getPositionY());
	this->addChild(app2);
	totalWidth += 4;
	totalWidth += app2->getContentSize().width;

	float bx = (s.width - totalWidth)*0.5;
	app1->setPositionX(bx);
	roundTip->setPositionX(app1->getPositionX()+app1->getContentSize().width+4);
	app2->setPositionX(roundTip->getPositionX()+roundTip->realWidth+4);

	CCSprite *app3 = CCSprite::create(g_sLifeNeedBGImage);
	app3->setAnchorPoint(ccp(0,0));
	app3->setPositionX(app1->getPositionX());
	app3->setPositionY(app2->getPositionY()-app2->getContentSize().height-20);
	this->addChild(app3);

	NumberSprite * needTip = NumberSprite::create("green60",need);
	needTip->setAnchorPoint(ccp(0,0));
	needTip->setPositionX(app3->getPositionX()+app3->getContentSize().width+4);
	needTip->setPositionY(app3->getPositionY());
	this->addChild(needTip);

	CCSprite *app4 = CCSprite::create(g_sLifeValueBGImage);
	app4->setAnchorPoint(ccp(0,0));
	app4->setPositionX(needTip->getPositionX()+needTip->realWidth+4);
	app4->setPositionY(needTip->getPositionY());
	this->addChild(app4);

	CCMenuItemImage* pSureMenu = CCMenuItemImage::create(
                                                g_sSureBGImage, 
                                                g_sSureBGImage, 
                                                this, 
                                                menu_selector(ChallengeAgainLayer::onCommandSure));
	pSureMenu->setAnchorPoint(ccp(0,0));
	CCMenu* pMenu = CCMenu::create(pSureMenu, NULL);
    this->addChild(pMenu);
	pMenu->setTouchPriority(-1000);
	pMenu->setAnchorPoint(ccp(0,0));
	pMenu->setPositionY(app4->getPositionY()-app4->getTextureRect().size.height-40);
	pMenu->setPositionX(100);


	CCSprite * img = CCSprite::create(g_sReturnBGImage);
	CCMenuItemImage* pReturnMenu = CCMenuItemImage::create(
                                                g_sReturnBGImage, 
                                                g_sReturnBGImage, 
                                                this, 
                                                menu_selector(ChallengeAgainLayer::onCommandReturn));
	pReturnMenu->setAnchorPoint(ccp(0,0));
	CCMenu* pMenu2 = CCMenu::create(pReturnMenu, NULL);
    this->addChild(pMenu2);
	pMenu2->setTouchPriority(-1000);
	pMenu2->setAnchorPoint(ccp(0,0));
	pMenu2->setPositionY(pMenu->getPositionY());
	pMenu2->setPositionX(s.width-img->getTextureRect().size.width-100);
}
Ejemplo n.º 3
0
void BaseScene::buildHeader(int highlightIndex, const char* title, const char* description)
{
    _currentMenuIndex = highlightIndex;
    
    CCMenuItemImage* homeButton = CCMenuItemImage::create();
    homeButton->setNormalSpriteFrame(CCSpriteFrameCache::sharedSpriteFrameCache()->spriteFrameByName("btn_home_nrl"));
    homeButton->setSelectedSpriteFrame(CCSpriteFrameCache::sharedSpriteFrameCache()->spriteFrameByName("btn_home_prd"));
    homeButton->setDisabledSpriteFrame(CCSpriteFrameCache::sharedSpriteFrameCache()->spriteFrameByName("btn_home_prd"));
    homeButton->setTarget(this, menu_selector(BaseScene::loadHomeScene));
    homeButton->setAnchorPoint(ccp(1.0f, 1.0f));
    
    CCMenuItemImage* fbActionButton = CCMenuItemImage::create();
    fbActionButton->setNormalSpriteFrame(CCSpriteFrameCache::sharedSpriteFrameCache()->spriteFrameByName("btn_fb_action_nrl"));
    fbActionButton->setSelectedSpriteFrame(CCSpriteFrameCache::sharedSpriteFrameCache()->spriteFrameByName("btn_fb_action_prd"));
    fbActionButton->setDisabledSpriteFrame(CCSpriteFrameCache::sharedSpriteFrameCache()->spriteFrameByName("btn_fb_action_dis"));
    fbActionButton->setTarget(this, menu_selector(BaseScene::loadFBActionScene));
    fbActionButton->setAnchorPoint(ccp(1.0f, 1.0f));
    
    if (EziSocialObject::sharedObject()->isFacebookSessionActive() == false)
    {
        fbActionButton->setEnabled(false);
    }
    
    CCMenuItemImage* helpButton = CCMenuItemImage::create();
    helpButton->setNormalSpriteFrame(CCSpriteFrameCache::sharedSpriteFrameCache()->spriteFrameByName("btn_help_nrl"));
    helpButton->setSelectedSpriteFrame(CCSpriteFrameCache::sharedSpriteFrameCache()->spriteFrameByName("btn_help_prd"));
    helpButton->setDisabledSpriteFrame(CCSpriteFrameCache::sharedSpriteFrameCache()->spriteFrameByName("btn_help_prd"));
    helpButton->setTarget(this, menu_selector(BaseScene::loadHelpScene));
    
    helpButton->setAnchorPoint(ccp(1.0f, 1.0f));
    
    switch (highlightIndex)
    {
        case 0:
            homeButton->setEnabled(false);
            break;
            
        case 1:
            fbActionButton->setEnabled(false);
            break;
            
        case 2:
            helpButton->setEnabled(false);
            break;
            
        default:
            break;
    }
    
    
    CCMenu* homeMenu = CCMenu::create(homeButton, fbActionButton, helpButton, NULL);
    homeMenu->alignItemsHorizontally();
    
    this->addChild(homeMenu);
    PlaceNode(homeMenu, 0.88, 0.98);
    
    // Add a line.
    CCLayerColor* lineLayer = CCLayerColor::create(ccc4(204, 204, 204, 204),
                                                   CCDirector::sharedDirector()->getVisibleSize().width,
                                                   1.0 * AppDelegate::SCREEN_SCALE_FACTOR);
    
    this->addChild(lineLayer);
    PlaceNode(lineLayer, 0.0, 0.8);
    lineLayer->setPositionY(homeMenu->getPositionY() - homeButton->getContentSize().height - (7 * AppDelegate::SCREEN_SCALE_FACTOR));
    
    // Add Title
    CCLabelTTF* titleLabel = CCLabelTTF::create(title, "Arial", 50.0 * AppDelegate::SCREEN_SCALE_FACTOR);
    this->addChild(titleLabel);
    titleLabel->setAnchorPoint(ccp(0.0f, 0.0f));
    //PlaceNode(titleLabel, 0.02, 0.98);
    
    CCLabelTTF* descriptionLabel = CCLabelTTF::create(description,
                                                      "Arial", SCALED_VALUE(22.0f));
    this->addChild(descriptionLabel);
    descriptionLabel->setAnchorPoint(ccp(0.0f, 0.0f));
    PlaceNode(descriptionLabel, 0.02, 0.98);
    descriptionLabel->setPositionY(homeMenu->getPositionY() - homeButton->getContentSize().height);
    descriptionLabel->setColor(ccc3(204, 204, 204));
    
    titleLabel->cocos2d::CCNode::setPosition(descriptionLabel->getPositionX(),
                                             descriptionLabel->getPositionY() + descriptionLabel->getContentSize().height - 2.0f);
    
}