Ejemplo n.º 1
0
// *************************************************************************************************
// Layer Init
// *************************************************************************************************
// on "init" you need to initialize your instance
bool HelloWorld::init()
{
	//////////////////////////////
	// 1. super init first
	if ( !CCLayer::init() )
	{
		return false;
	}
    this->setIsTouchEnabled(true);
    this->setIsKeypadEnabled(true);
    
    Depth = 0;
    // LayerColor 初始化
    this->initWithColor(ccc4f(0,0,0,150));
    this->setContentSize(CCSizeMake(WorkSize_W, WorkSize_H));
    this->setIsVisible(true);
    
    CCSpriteFrameCache::sharedSpriteFrameCache()->addSpriteFramesWithFile("Common.plist");
	CCSpriteBatchNode *spriteCommon = CCSpriteBatchNode::batchNodeWithFile("Common.png");
	spriteCommon->getTextureAtlas()->resizeCapacity(50);
	addChild(spriteCommon);
    
	/////////////////////////////
	// 2. add a menu item with "X" image, which is clicked to quit the program
	//    you may modify it.

	// add a "close" icon to exit the progress. it's an autorelease object
	CCMenuItemImage *pCloseItem = CCMenuItemImage::itemFromNormalImage(
										"CloseNormal.png",
										"CloseSelected.png",
										this,
										menu_selector(HelloWorld::menuCloseCallback) );
	pCloseItem->setPosition( ccp(WorkSize_W - 20, 20) );
	CCMenu* pMenu = CCMenu::menuWithItems(pCloseItem, NULL);
	pMenu->setPosition( CCPointZero );
	this->addChild(pMenu);
    

	CCLabelTTF* pLabel = CCLabelTTF::labelWithString("Hello World", "Thonburi", 50);
	pLabel->setPosition( ccp(WorkSize_W/ 2, WorkSize_H - 20) );
	this->addChild(pLabel);

    // 商店進入鈕
    CCMenuItemImage *StoreItem = CCMenuItemImage::itemFromNormalImage(
                                                   "HelloWorld.png",
                                                   "HelloWorld.png",
                                                   this,
                                                   menu_selector(HelloWorld::StoreButtonCallback));
	StoreItem->setPosition( ccp(WorkSize_W/2, WorkSize_H/2) );
	StoreMenu = CCMenu::menuWithItems(StoreItem, NULL);
	StoreMenu->setPosition( CCPointZero );
	this->addChild(StoreMenu);
    
    // 商店介面
    spriteStoreBG = CCSprite::spriteWithSpriteFrameName("ui_shop_01.png");
    spriteStoreBG->setPosition(fcp(Rectx, Recty));
    spriteStoreBG->setIsVisible(false);
    this->addChild(spriteStoreBG, Depth++);
    
    
    // 商店離開鈕
    CCMenuItem *StoreExitItem = CCMenuItemSprite::itemFromNormalSprite(
                                   CCSprite::spriteWithSpriteFrameName("ui_shop_04.png"), CCSprite::spriteWithSpriteFrameName("ui_shop_04.png"), this, menu_selector(HelloWorld::StoreExitBtnCallback));
    CCMenu *StoreExitMenu = CCMenu::menuWithItem(StoreExitItem);
    StoreExitMenu->setPosition(ccp(StoreExitx, StoreExity));
    spriteStoreBG->addChild(StoreExitMenu);
    
    // 準備商店項目素材
    frameStoreItems[0] = CCSpriteFrameCache::sharedSpriteFrameCache()->spriteFrameByName("ui_shop_02.png"); // 金幣
    frameStoreItems[1] = CCSpriteFrameCache::sharedSpriteFrameCache()->spriteFrameByName("ui_shop_03.png"); // 籌碼
    // 商店項目
    for(int a = 0; a < MAX_IAP_NUM; a++)
    {
        // 商品項目
        spriteStoreItems[a] = CCSprite::spriteWithSpriteFrame(frameStoreItems[0]);
        spriteStoreItems[a]->setPosition(ccp(StoreItemx[a], StoreItemy[a]));
        spriteStoreItems[a]->setOpacity(255);
        spriteStoreItems[a]->setIsVisible(false);
        spriteStoreBG->addChild(spriteStoreItems[a], a);
        
        // 商品內容
        labelItemContent[a] = CCLabelTTF::labelWithString("------", "arial", ItemContentFrontSize);
        labelItemContent[a]->setColor(ccWHITE);
        labelItemContent[a]->setPosition(ccp(ItemContentx[a],ItemContenty[a]));
        spriteStoreItems[a]->addChild(labelItemContent[a]);
        
        // 商項目購買金額初始化
        labelItemPrice[a] = CCLabelTTF::labelWithString("------", "arial", ItemPriceFrontSize);
        labelItemPrice[a]->setColor(ccWHITE);
        labelItemPrice[a]->setPosition(ccp(ItemPricex[a],ItemPricey[a]));
        spriteStoreItems[a]->addChild(labelItemPrice[a]);
    }
    
    // 商店Loading背景
    spriteLoadingBG = CCSprite::spriteWithSpriteFrameName("loading10.png");
    spriteLoadingBG->setPosition(fcp(LoadingBGx, LoadingBGy));
    spriteLoadingBG->setIsVisible(false);
    spriteLoadingBG->setScale(0.3f);
    this->addChild(spriteLoadingBG, Depth++);
    // 商店Loading背景動畫
    spriteLoadingBG->runAction(CCRepeatForever::actionWithAction(CCRotateBy::actionWithDuration(1.0f, 360.0f)));
    
    // 商店Loading文字(讀取中...)
    spriteLoading = CCSprite::spriteWithSpriteFrameName("loading01.png");
    spriteLoading->setPosition(fcp(Loadingx, Loadingy));
    spriteLoading->setIsVisible(false);
    this->addChild(spriteLoading, Depth++);
    // 商店Loading文字字(讀取中...)動畫
    CCAnimation* animation = CCAnimation::animation();
    animation->setDelay(0.1f);
    for(int a = 0; a < 8; a++)
    {
        a < 1 ?
        sprintf(ResourceName, "loading%02d.png", 1):
        sprintf(ResourceName, "loading%02d.png", a);
        
        animation->addFrame(CCSpriteFrameCache::sharedSpriteFrameCache()->spriteFrameByName(ResourceName));
        spriteLoading->runAction(CCRepeatForever::actionWithAction(CCAnimate::actionWithAnimation(animation, true)));
    }
	
	return true;
}