Exemple #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;
}
Exemple #2
0
void Background::OnDead(enUnitIndex target, CCPoint targetPos)
{
    enUnitType eType = GlobalData::sharedDirector()->getUnitTypeByIndex(target);
    unitDataMap unitData = GlobalData::sharedDirector()->getUnitDefaultData();
//    unitPosMap unitsPos = GlobalData::sharedDirector()->getUnitPos();
    
    if(eType==enUnitTypeTroopMine ||
       eType==enUnitTypeTroopEnemy)
    {
        CCNodeLoaderLibrary * ccNodeLoaderLibrary = CCNodeLoaderLibrary::newDefaultCCNodeLoaderLibrary();
        CCBReader * ccbReader = new CCBReader(ccNodeLoaderLibrary);
        CCNode * ccbNode = ccbReader->readNodeGraphFromFile(unitData[eType].strCCBI.c_str(), this);
        CCBAnimationManager* animationManager = ccbReader->getAnimationManager();
        animationManager->runAnimationsForSequenceNamed("dead");
        ccbReader->release();
        ccbNode->setScaleX(0.5);//the bg sprite in ccb is scale.
        
        if(target<enUnitIndexEnemy1)
        {
            m_backgroundLeft->addChild(ccbNode);
            ccbNode->setPosition(m_backgroundLeft->convertToNodeSpace(targetPos));
            m_CraterArrayLeft->addObject(ccbNode);
        }
        else
        {
            m_backgroundRight->addChild(ccbNode);
            ccbNode->setPosition(m_backgroundRight->convertToNodeSpace(targetPos));
            m_CraterArrayRight->addObject(ccbNode);
        }
    }
    else if(eType==enUnitTypeCarMine ||
            eType==enUnitTypeCarEnemy)
    {
        CCNodeLoaderLibrary * ccNodeLoaderLibrary = CCNodeLoaderLibrary::newDefaultCCNodeLoaderLibrary();
        CCBReader * ccbReader = new CCBReader(ccNodeLoaderLibrary);
        CCNode * ccbNode = ccbReader->readNodeGraphFromFile("ccb/boom.ccbi", this);
        CCBAnimationManager* animationManager = ccbReader->getAnimationManager();
        animationManager->runAnimationsForSequenceNamed("boom");
        ccbReader->release();
        ccbNode->setScaleX(0.5);//the bg sprite in ccb is scale.
        
        if(target<enUnitIndexEnemy1)
        {
            m_backgroundLeft->addChild(ccbNode);
            ccbNode->setPosition(m_backgroundLeft->convertToNodeSpace(targetPos));
            m_CraterArrayLeft->addObject(ccbNode);
        }
        else
        {
            m_backgroundRight->addChild(ccbNode);
            ccbNode->setPosition(m_backgroundRight->convertToNodeSpace(targetPos));
            m_CraterArrayRight->addObject(ccbNode);
        }
    }
}
void LayerChonBanChoi::onButtonCreate(CCObject* pSender)
{
    CCLOG("onButtonUpdate ");
    //Check
    boost::shared_ptr<double> am, amf;
    boost::shared_ptr<User> myself = GameServer::getSingleton().getSmartFox()->MySelf();
    if( myself==NULL || myself->GetVariable("am")==NULL || myself->GetVariable("amf")==NULL ){
        return;
    }
    amf = myself->GetVariable("amf")->GetDoubleValue();
    if((*amf/4)<1000){
		CCLOG("Không đủ tiền tạo phòng!");
		Chat *toast = new Chat("Bạn không đủ tiền tạo phòng!!", -1);
		this->addChild(toast);
        return;
    }
    
	CCNodeLoaderLibrary* ccNodeLoaderLibrary = SceneManager::getSingleton().getNodeLoaderLibrary();
	CCBReader* ccbReader = new cocos2d::extension::CCBReader(ccNodeLoaderLibrary);
    LayerCreateRoom* mLayer;
    if (ccbReader)
    {
        mLayer = (LayerCreateRoom *)ccbReader->readNodeGraphFromFile( "LayerCreateRoom.ccbi" );
        this->addChild(mLayer, 1, 1);
        ccbReader->release();
    }
    mLayer->setGameID(m_gID);
}
Exemple #4
0
bool AppDelegate::applicationDidFinishLaunching() {
    // initialize director
    auto director = Director::getInstance();
    auto eglView = EGLView::getInstance();

    director->setOpenGLView(eglView);
    
    // turn on display FPS
    director->setDisplayStats(true);

    // set FPS. the default value is 1.0/60 if you don't call this
    director->setAnimationInterval(1.0 / 60);
    
    // create a scene. it's an autorelease object
    auto scene = Scene::create();
#if 0
    NodeLoaderLibrary *pLoaderLibrary = NodeLoaderLibrary::newDefaultNodeLoaderLibrary();
    CCBReader *ccbReader = new CCBReader(pLoaderLibrary);
    pLoaderLibrary->registerNodeLoader("plane_figtht_main", XCMainMenuLoader::loader());
    Node *pMainMenu = ccbReader->readNodeGraphFromFile("ccb/ccbi/plane_fight_main.ccbi");
    dynamic_cast<XCMainMenu*>(pMainMenu)->setAnimationManager(ccbReader->getAnimationManager());
    dynamic_cast<XCMainMenu*>(pMainMenu)->initPlaneMain();
    ccbReader->release();
    scene->addChild(pMainMenu); 
#else
    
#endif
    
    // run
    director->runWithScene(scene);

    return true;
}
bool TitleScene::init()
{
    CCLOG("TitleScene::init()");
    if ( !Layer::init() )
    {
        return false;
    }
    // BGM・SEのプリロード
    SimpleAudioEngine::getInstance()->preloadBackgroundMusic(BGM_TITLE);
    SimpleAudioEngine::getInstance()->preloadEffect(SE_TOUCH_NORMAL);
    
    // タイトルのccbiファイルを読み込む
    auto nodeLoaderLibrary = NodeLoaderLibrary::getInstance();
    CCBReader* reader = new CCBReader(nodeLoaderLibrary);
    auto TitleNode = reader->readNodeGraphFromFile("ccbi/TitleScene.ccbi");
    
    // 追加
    this->addChild(TitleNode, 0);
    
    // 開放
    reader->release();
    
    // シングルタップのみ受付
    setTouchEnabled(true);
    setTouchMode(Touch::DispatchMode::ONE_BY_ONE);

    return true;
}
bool AppDelegate::applicationDidFinishLaunching() {
    // initialize director
    CCDirector* pDirector = CCDirector::sharedDirector();
    CCEGLView* pEGLView = CCEGLView::sharedOpenGLView();

    pDirector->setOpenGLView(pEGLView);
	
    // デザインサイズの設定
    pEGLView->setDesignResolutionSize(designResolutionSize.width, designResolutionSize.height, kResolutionNoBorder);

    CCSize frameSize = pEGLView->getFrameSize();

    std::vector<std::string> searchPath;

    if (frameSize.height > largeResource.size.height)
    {
        // iPad Retina用リソースを使用
        searchPath.push_back(xlargeResource.directory);
        pDirector->setContentScaleFactor(MIN(xlargeResource.size.height / designResolutionSize.height, xlargeResource.size.width / designResolutionSize.width));
    }
    else if (frameSize.height > smallResource.size.height)
    {
        // iPad用リソースを使用
        searchPath.push_back(largeResource.directory);
        pDirector->setContentScaleFactor(MIN(largeResource.size.height / designResolutionSize.height, largeResource.size.width / designResolutionSize.width));
    }
    else
    {
        // iPhone用リソースを使用
        searchPath.push_back(smallResource.directory);
        pDirector->setContentScaleFactor(MIN(smallResource.size.height / designResolutionSize.height, smallResource.size.width / designResolutionSize.width));
    }

    // リソースディレクトリを指定
    CCFileUtils::sharedFileUtils()->setSearchPaths(searchPath);

    // turn on display FPS
    pDirector->setDisplayStats(true);

    // set FPS. the default value is 1.0/60 if you don't call this
    pDirector->setAnimationInterval(1.0 / 60);

    // CocosBuilderのファイルを読み込みゲーム画面を生成する
    CCNodeLoaderLibrary* ccNodeLoaderLibrary = CCNodeLoaderLibrary::newDefaultCCNodeLoaderLibrary();
    ccNodeLoaderLibrary->registerCCNodeLoader("GameLayer", GameLayerLoader::loader());
    CCBReader* ccbReader = new CCBReader(ccNodeLoaderLibrary);
    CCNode* node = ccbReader->readNodeGraphFromFile("GameLayer.ccbi");
    ((GameLayer*)node)->setAnimationManager(ccbReader->getAnimationManager());

    // シーンを用意し、ゲーム画面を設置する
    CCScene* pScene = CCScene::create();
    if (node != NULL)
        pScene->addChild(node);
    ccbReader->release();

    // run
    pDirector->runWithScene(pScene);

    return true;
}
Exemple #7
0
bool Unit::Init(enUnitType eType, enUnitIndex eIndex)
{
    do
    {
        unitDataMap unitData = GlobalData::sharedDirector()->getUnitDefaultData();
        m_unitData = unitData[eType];
        
        m_nFireCd = m_unitData.nFireCD;
        m_eUnitType = m_unitData.eType;
        m_eUnitStatus = enUnitStatusPre;
        m_nHp = m_unitData.nHp;
        m_eUnitIndex = eIndex;
        
        CCNodeLoaderLibrary * ccNodeLoaderLibrary = CCNodeLoaderLibrary::newDefaultCCNodeLoaderLibrary();
        CCBReader * ccbReader = new CCBReader(ccNodeLoaderLibrary);
        CCNode * ccbNode = ccbReader->readNodeGraphFromFile(m_unitData.strCCBI.c_str(), this);
        m_animationManager = ccbReader->getAnimationManager();
        m_animationManager->runAnimationsForSequenceNamed("run");
        m_animationManager->setAnimationCompletedCallback(this, callfunc_selector(Unit::AnimationCallBack));
        ccbReader->release();
        
        addChild(ccbNode);
        return true;
    } while (false);
    CCLog("Function Unit::Init Error!");
    return false;
}
Exemple #8
0
//---------------------------------------
//	カスタムクラスのパーツの取得(クラス名指定あり)
//---------------------------------------
CCNode* SceneChanger::loadCustomParts(const char* className, const char* fileName, CCNodeLoader* loader) {
    CCNodeLoaderLibrary* ccNodeLoaderLibrary = CCNodeLoaderLibrary::newDefaultCCNodeLoaderLibrary();
    ccNodeLoaderLibrary->registerCCNodeLoader(className, loader);
    CCBReader* ccbReader = new CCBReader(ccNodeLoaderLibrary);
    CCString* file = CCString::createWithFormat("%s.ccbi", fileName);
    CCNode* node = ccbReader->readNodeGraphFromFile(file->getCString());
    ccbReader->release();
    return node;
}
bool BalloonRankDialog::init()
{
	bool bRet = false;
	do
	{
		CC_BREAK_IF(!DialogLayer::init());
		CCNodeLoaderLibrary* pLoaderLib = CCNodeLoaderLibrary::newDefaultCCNodeLoaderLibrary();

		CCBReader* pCCBReader = new CCBReader(pLoaderLib);

		std::string strCCBFileName = "BalloonRankDialog.ccbi";

		const std::vector<std::string> vSearchOrder = CCFileUtils::sharedFileUtils()->getSearchResolutionsOrder();

		std::string strCCBRootPath = vSearchOrder[0];

		pCCBReader->setCCBRootPath(strCCBRootPath.c_str());

		CCNode* pNode = pCCBReader->readNodeGraphFromFile(strCCBFileName.c_str(), this);

		if (pNode != NULL)
		{
			this->addChild(pNode);
		}

		pCCBReader->release();
		
		setKeypadEnabled(true);

		initLabelTTF();
        
        initTableView();
        
        initMenu();
        
        // start fire
        CCArray* pArrayFire = CCArray::createWithCapacity(6);
        for (int idx = 1; idx <= 6; ++idx)
        {
            pArrayFire->addObject(CCSpriteFrameCache::sharedSpriteFrameCache()->spriteFrameByName(CCString::createWithFormat("energy_fire%d.png", idx)->getCString()));
        }
        CCAnimation* pAnimation = CCAnimation::createWithSpriteFrames(pArrayFire, 0.1f);
        CCAnimate* pAnimateFire = CCAnimate::create(pAnimation);
        m_pSpriteScoreFire->runAction(CCRepeatForever::create(pAnimateFire));
        
        // set animation onEnter and onExit
        m_pMainBoard = m_pSpriteBoard;
        m_pSpriteBoard->setScale(0.01f);
        setOnEnterAction(CCEaseBounceOut::create(CCScaleTo::create(0.5f, 1.0f)));
        setOnExitAction(CCEaseExponentialIn::create(CCScaleTo::create(0.5f, 0.01f)));
		
		bRet = true;
		
	} while(0);
	
	return bRet;
}
CCScene* StoreBScene::getStoreBScene() {
    CCNodeLoaderLibrary * ccNodeLoaderLibrary = CCNodeLoaderLibrary::sharedCCNodeLoaderLibrary();

    ccNodeLoaderLibrary->registerCCNodeLoader("StoreBScene", StoreBSceneLoader::loader());

    CCBReader *ccbReader = new CCBReader(ccNodeLoaderLibrary);
    ccbReader->retain();
    CCScene *pScene = ccbReader->createSceneWithNodeGraphFromFile("ccb/StoreBScene.ccbi");
    ccbReader->release();
    return pScene;
}
Exemple #11
0
void BattleScene::initPauseLayer(){
    CCNodeLoaderLibrary *nodeLoaderLibrary = CCNodeLoaderLibrary::sharedCCNodeLoaderLibrary();
    CCBReader *reader = new CCBReader(nodeLoaderLibrary);
    
    pauseLayer = (PauseLayer *)reader->readNodeGraphFromFile("BattleScenePauseMenu.ccbi", this);
    pauseLayer->setBattleLayer(battleLayer);
    pauseLayer->hide();
    this->addChild(pauseLayer, PAUSE_LAYER_Z);
    
    reader->release();
}
Exemple #12
0
CCScene* BattleScene::scene(){
    CCNodeLoaderLibrary *nodeLoaderLibrary = CCNodeLoaderLibrary::sharedCCNodeLoaderLibrary();
    CCBReader *reader = new CCBReader(nodeLoaderLibrary);
    
    // 'scene' is an autorelease object.
    CCScene *scene = reader->createSceneWithNodeGraphFromFile("BattleScene.ccbi");

    reader->release();
    
    // return the scene
    return scene;
}
Exemple #13
0
void LayerFriend::gotoFriendDetails(){
    removeOldView();
	CCNodeLoaderLibrary* ccNodeLoaderLibrary = SceneManager::getSingleton().getNodeLoaderLibrary();
	CCBReader* ccbReader = new cocos2d::extension::CCBReader(ccNodeLoaderLibrary);
    LayerFriendDetails* mLayer;
    if (ccbReader)
    {
        mLayer = (LayerFriendDetails *)ccbReader->readNodeGraphFromFile( "LayerFriendDetails.ccbi" );
        nodeChild->addChild(mLayer, 1, 1);
        ccbReader->release();
    }
    currNodeView = mLayer;
}
Exemple #14
0
void LayerButtonInGame::eventTouchBtnSetting(CCObject *pObject, TouchEventType pType){
	if (pType == TOUCH_EVENT_ENDED){
		CCLOG("Click Setting");
		CCNodeLoaderLibrary* ccNodeLoaderLibrary = SceneManager::getSingleton().getNodeLoaderLibrary();
		CCBReader* ccbReader = new cocos2d::extension::CCBReader(ccNodeLoaderLibrary);
		LayerSettings* mLayerSettings;
		if (ccbReader)
		{
			mLayerSettings = (LayerSettings *)ccbReader->readNodeGraphFromFile( "LayerSettings.ccbi" );
			SceneManager::getSingleton().getLayerOnTop()->addChild(mLayerSettings, 1, 1);
			ccbReader->release();
		}
	}
}
Exemple #15
0
void Bomb::handleCollisionWith(GameObject *gameObject)
{
    if (dynamic_cast<Dragon*>(gameObject)) {
        // Collided with the dragon, remove object and add an explosion instead.
        this->setIsScheduledForRemove(true);
        
        CCNodeLoaderLibrary* ccNodeLoaderLibrary = CCNodeLoaderLibrary::sharedCCNodeLoaderLibrary();
        CCBReader* ccbReader = new CCBReader(ccNodeLoaderLibrary);
        CCNode* pExplosion = ccbReader->readNodeGraphFromFile("Explosion.ccbi");
        pExplosion->setPosition(this->getPosition());
        this->getParent()->addChild(pExplosion);
        ccbReader->release();
    }
}
CCNode* AbstractNodeProvider::getNodeFromCcbFile(const char* pCcbFileName) {
    CCBReader* pReader = new CCBReader(CCNodeLoaderLibrary::sharedCCNodeLoaderLibrary());
    pReader->setCCBResourcePostfix(getResourcePostfix());
	CCNode* pNode = pReader->readNodeGraphFromFile(pCcbFileName);

    AnimationManagerAssigner *pAnimationManagerAssigner = dynamic_cast<AnimationManagerAssigner *>(pNode);
    if (pAnimationManagerAssigner != NULL) {
        pAnimationManagerAssigner->setAnimationManagers(pReader->getAnimationManagers());
    }

	pReader->release();

	return pNode;
}
Exemple #17
0
Bomb* Bomb::bomb()
{
    CCNodeLoaderLibrary *nodeLibrary = CCNodeLoaderLibrary::newDefaultCCNodeLoaderLibrary();
    nodeLibrary->registerCCNodeLoader("Bomb", BombLoader::loader());
    CCBReader *ccbReader = new CCBReader(nodeLibrary);
    Bomb *node = (Bomb *)ccbReader->readNodeGraphFromFile("ccb/bomb");
    ccbReader->getAnimationManager()->setAnimationCompletedCallback(node, callfunc_selector(Bomb::test));
    ccbReader->release();
    
//    CCBAnimationManager * ccbManager = (CCBAnimationManager *)node->getUserObject();
//    ccbManager->setAnimationCompletedCallback(node, callfunc_selector(Bomb::test));
    
    return node;
}
Exemple #18
0
void LiquidScene::tappedPreviousButton(Object* pSender, Control::EventType pControlEventType)
{
    CCLOG("tappedPreviousButton eventType = %d", pControlEventType);
    NodeLoaderLibrary* nodeLoaderLibrary = NodeLoaderLibrary::getInstance();
    nodeLoaderLibrary->registerNodeLoader("OpeningLayer", OpeningLayerLoader::loader());
    CCBReader* ccbReader = new CCBReader(nodeLoaderLibrary);
    Node* node = ccbReader->readNodeGraphFromFile("Opening.ccbi");
    Scene* scene = Scene::create();
    if (node != NULL)
    {
        scene->addChild(node);
    }
    ccbReader->release();
    Director::getInstance()->replaceScene(scene);
}
Exemple #19
0
bool CLoginLayer::init()
{
    CCLayer::init() ;
    m_pAccount = m_pPassWord = NULL ;
    CCNodeLoaderLibrary* pLiberay =  CCNodeLoaderLibrary::sharedCCNodeLoaderLibrary() ;
    CCBReader* pReader =  new CCBReader(pLiberay);
    CCNode* pnode = pReader->readNodeGraphFromFile("UIScene/Login.ccbi", this) ;
    addChild(pnode) ;
    pReader->release() ;
//    CCSprite* pgirl = CCSprite::create("iphone/linkingscene_logo.png") ;
//    pgirl->setAnchorPoint(ccp(0,0));
//    pgirl->setPosition(ccp(8.0,-7));
//    addChild(pgirl) ;
    return true ;
}
Exemple #20
0
void LayerFriend::gotoInviteFriends(){
   
	CCNodeLoaderLibrary* ccNodeLoaderLibrary = SceneManager::getSingleton().getNodeLoaderLibrary();
	CCBReader* ccbReader = new cocos2d::extension::CCBReader(ccNodeLoaderLibrary);
	ccbReader = new cocos2d::extension::CCBReader(ccNodeLoaderLibrary);
	LayerInviteFriends* mLayer;
	if (ccbReader)
	{
		mLayer = (LayerInviteFriends *)ccbReader->readNodeGraphFromFile( "LayerInviteFriends.ccbi" );
		nodeChild->getParent()->addChild(mLayer, 1, 1);
		ccbReader->release();
		mLayer->setZOrder(INT_MAX);
	}
   

}
Exemple #21
0
void LayerButtonInGame::eventTouchBtnCoin(CCObject *pObject, TouchEventType pType){
	if (pType == TOUCH_EVENT_ENDED){
		CCLOG("Click Coin"); 
		//
		CCNodeLoaderLibrary* ccNodeLoaderLibrary = SceneManager::getSingleton().getNodeLoaderLibrary();
		CCBReader* ccbReader = new cocos2d::extension::CCBReader(ccNodeLoaderLibrary);
		LayerChargeMoney* mLayer;
		if (ccbReader)
		{
			mLayer = (LayerChargeMoney *)ccbReader->readNodeGraphFromFile( "LayerPopupChargeMoney.ccbi" );
			mLayer->setIsPopup(true);
			this->getParent()->addChild(mLayer, 1, 1);
			mLayer->setTouchEnabled(true);
			ccbReader->release();
		}
	}
}
CCScene* CCB_CLASS_NAME1::scene()
{
	CCScene *sc = CCScene::create();
	CCNodeLoaderLibrary* ccNodeLoaderLibrary = CCNodeLoaderLibrary::sharedCCNodeLoaderLibrary();
	ccNodeLoaderLibrary->registerCCNodeLoader(XStr(CCB_CLASS_NAME1), XConn(CCB_CLASS_NAME1, BuilderLoad)::loader());
    
	CCBReader* ccbReader = new CCBReader(ccNodeLoaderLibrary);
	CCNode* node = ccbReader->readNodeGraphFromFile("ios/ccbResources/" XStr(CCB_CLASS_NAME1) ".ccbi", sc);
    
	
    ccbReader->release();
    
	if (node) {
        sc->addChild(node,1,DefaultLayerTag);
    }
    
	return sc;
}
bool BalloonOptionsDialog::init()
{
    // TODO:
    bool bRet = false;
    do
    {
        CC_BREAK_IF(!DialogLayer::init());
        // 加载ccbi
        CCNodeLoaderLibrary* pLoaderLib = CCNodeLoaderLibrary::newDefaultCCNodeLoaderLibrary();

        CCBReader* pCCBReader = new CCBReader(pLoaderLib);

        // 对应ccbi文件
        std::string strCCBFileName = "BalloonOptionsDialog.ccbi";

        // 得到第一个搜索路径
        const std::vector<std::string> vSearchOrder = CCFileUtils::sharedFileUtils()->getSearchResolutionsOrder();

        // 本程序中是对应的第一个元素即为对应的资源路径
        std::string strCCBRootPath = vSearchOrder[0];

        // 设置CCB的资源路径
        pCCBReader->setCCBRootPath(strCCBRootPath.c_str());

        CCNode* pNode = pCCBReader->readNodeGraphFromFile(strCCBFileName.c_str(), this);

        if (pNode != NULL)
        {
            this->addChild(pNode);
        }

        pCCBReader->release();

        initMenuItem();

        SetVisibleBoard(m_pSpriteBoard);

        bRet = true;

    } while(0);

    return bRet;
}
Exemple #24
0
bool AppDelegate::applicationDidFinishLaunching() {
    // initialize director
    auto director = Director::getInstance();
    auto eglView = EGLView::getInstance();

    director->setOpenGLView(eglView);

    // turn on display FPS
    director->setDisplayStats(false);

    // set FPS. the default value is 1.0/60 if you don't call this
    director->setAnimationInterval(1.0 / 60);

    // create a scene. it's an autorelease object
    //auto scene = HelloWorld::createScene();

    // とりあえずiPhone4S以上対応なので解像度系はiphone5で対応
    Resource res  = iphone5;
    std::vector<std::string> searchPath;
    searchPath.push_back(res.directory);
    auto fileutil = FileUtils::getInstance();
    fileutil->setSearchResolutionsOrder(searchPath);
    eglView->setDesignResolutionSize(res.size.width, res.size.height, ResolutionPolicy::FIXED_WIDTH);
    director->setContentScaleFactor(res.scaleFactor);

    // ccbiのロード
    NodeLoaderLibrary* nodeLoaderLibrary = NodeLoaderLibrary::getInstance();
    nodeLoaderLibrary->registerNodeLoader("OpeningLayer", OpeningLayerLoader::loader());
    CCBReader* ccbReader = new CCBReader(nodeLoaderLibrary);
    Node* node = ccbReader->readNodeGraphFromFile("Opening.ccbi");
    Scene* scene = Scene::create();
    if (node != NULL)
    {
        scene->addChild(node);
    }
    ccbReader->release();

    // run
    director->runWithScene(scene);

    return true;
}
bool AppDelegate::applicationDidFinishLaunching() {
    // initialize director
    CCDirector* pDirector = CCDirector::sharedDirector();
    CCEGLView* pEGLView = CCEGLView::sharedOpenGLView();

    pDirector->setOpenGLView(pEGLView);
	

    // マルチレゾリューション対応 START
    // Set the design resolution
    pEGLView->setDesignResolutionSize(designResolutionSize.width, designResolutionSize.height, kResolutionShowAll);
    
	CCSize frameSize = pEGLView->getFrameSize();
    
    std::vector<std::string> searchPath;
    
    // In this demo, we select resource according to the frame's height.
    // If the resource size is different from design resolution size, you need to set contentScaleFactor.
    // We use the ratio of resource's height to the height of design resolution,
    // this can make sure that the resource's height could fit for the height of design resolution.
    
    
    cocos2d::CCLog("-------");
    cocos2d::CCLog("height:%f", frameSize.height);
    cocos2d::CCLog("width:%f", frameSize.width);
	if (frameSize.height > largeResource.size.height)
	{
        cocos2d::CCLog("xlargeResource");
        searchPath.push_back(xlargeResource.directory);
        pDirector->setContentScaleFactor(MIN(xlargeResource.size.height/designResolutionSize.height, xlargeResource.size.width/designResolutionSize.width));
	}
    else if (frameSize.height > smallResource.size.height)
    {
        cocos2d::CCLog("largeResource");
        searchPath.push_back(largeResource.directory);
        pDirector->setContentScaleFactor(MIN(largeResource.size.height/designResolutionSize.height, largeResource.size.width/designResolutionSize.width));
    }
	else
    {
        cocos2d::CCLog("smallResource");
        searchPath.push_back(smallResource.directory);
        pDirector->setContentScaleFactor(MIN(smallResource.size.height/designResolutionSize.height, smallResource.size.width/designResolutionSize.width));
    }
    
    
    // デバッグログ
    for (std::vector<std::string>::iterator itiElement = searchPath.begin(); itiElement != searchPath.end(); ++itiElement) {
        std::string iElement = *itiElement;      // itiElement を使って繰り返し、配列要素を扱う。
        cocos2d::CCLog("searchPath:%s", iElement.c_str());
    }
    float scale = pDirector->getContentScaleFactor();
    cocos2d::CCLog("scale:%f", scale);

    
    // set searching path
    CCFileUtils::sharedFileUtils()->setSearchPaths(searchPath);
    // マルチレゾリューション対応 END
    
    
    // turn on display FPS
    pDirector->setDisplayStats(true);

    // set FPS. the default value is 1.0/60 if you don't call this
    pDirector->setAnimationInterval(1.0 / 60);
    
    
    // cocos builder 読み込み
    CCNodeLoaderLibrary* ccNodeLoaderLibrary = CCNodeLoaderLibrary::newDefaultCCNodeLoaderLibrary();
    ccNodeLoaderLibrary->registerCCNodeLoader("MenuLayer", MenuLayerLoader::loader());
    CCBReader* ccbReader = new CCBReader(ccNodeLoaderLibrary);
    CCNode* node = ccbReader->readNodeGraphFromFile("MenuLayer.ccbi");
    
    CCScene* pScene = CCScene::create();
    if (node != NULL) {
        pScene->addChild(node);
    }
    ccbReader->release();

    // run
    pDirector->runWithScene(pScene);

    return true;
}
bool BalloonResultDialog::init()
{
	bool bRet = false;
	do
	{
		CC_BREAK_IF(!DialogLayer::init());
		// 加载ccbi
		CCNodeLoaderLibrary* pLoaderLib = CCNodeLoaderLibrary::newDefaultCCNodeLoaderLibrary();

		CCBReader* pCCBReader = new CCBReader(pLoaderLib);

		// 对应ccbi文件
		std::string strCCBFileName = "BalloonResultDialog.ccbi";

		// 得到第一个搜索路径
		const std::vector<std::string> vSearchOrder = CCFileUtils::sharedFileUtils()->getSearchResolutionsOrder();

		// 本程序中是对应的第一个元素即为对应的资源路径
		std::string strCCBRootPath = vSearchOrder[0];

		// 设置CCB的资源路径
		pCCBReader->setCCBRootPath(strCCBRootPath.c_str());

		CCNode* pNode = pCCBReader->readNodeGraphFromFile(strCCBFileName.c_str(), this);

		if (pNode != NULL)
		{
			this->addChild(pNode);
		}

		pCCBReader->release();
		
        initMenuTop();
        
        pushMenu(m_pMenuShare);
        
        // 设置按钮按下后变大的效果
        ControlUtil::sharedControlUtil()->SetMenuItemSelectedImageWithNormalImage(m_pMenuShare);
        
        /*
        // 初始化位置
        m_posOri = m_pSpriteResultBoard->getPosition();
        CCPoint posUp = ccp(m_pSpriteResultBoard->getPositionX(), getContentSize().height*2);
        
        // 进场动画
        m_pSpriteResultBoard->setPosition(posUp);
        
        addBoardChildWithAction(m_pSpriteResultBoard,
                                CCEaseBounceOut::create(CCMoveTo::create(0.5f, m_posOri)),
                                CCEaseExponentialIn::create(CCMoveTo::create(0.2f, posUp)));
        SetVisibleBoard(NULL);
        */
        m_pSpriteResultBoard->setScale(0.1f);
        setOnEnterAction(CCEaseBounceOut::create(CCScaleTo::create(0.5f, 1.0f)));
        setOnExitAction(CCEaseExponentialOut::create(CCScaleTo::create(0.3f, 0.1f)));
        m_pMainBoard = m_pSpriteResultBoard;
        
        // 更新分享按钮数据
        m_posShareItemOri = m_pMenuItemShare->getPosition();
        m_fShareItemAngleOri = m_pMenuItemShare->getRotation();
        // 默认隐藏新记录标志
        setNewFlagVisible(false);
        
        initLabelTTF();
        
		bRet = true;
		
	} while(0);
	
	return bRet;
}
Exemple #27
0
Panel* loadCCBFromFileToFenneX(const char* file, const char* inPanel, int zIndex)
{
    if(inPanel == NULL)
    {
        animManagers.clear();
    }
    NodeLoaderLibrary * nodeLoaderLibrary = NodeLoaderLibrary::newDefaultNodeLoaderLibrary();
    nodeLoaderLibrary->registerNodeLoader("CustomSprite", CustomSpriteLoader::loader());
    nodeLoaderLibrary->registerNodeLoader("CustomScaleSprite", CustomScaleSpriteLoader::loader());
    nodeLoaderLibrary->registerNodeLoader("CustomNode", CustomNodeLoader::loader());
    nodeLoaderLibrary->registerNodeLoader("CustomInput", CustomInputLoader::loader());
    nodeLoaderLibrary->registerNodeLoader("CustomLabel", CustomLabelLoader::loader());
    nodeLoaderLibrary->registerNodeLoader("CustomDropDownList", CustomDropDownListLoader::loader());
    CCBReader *ccbReader = new CCBReader(nodeLoaderLibrary);
    
    //IF this one fail, it needs to be silent
    bool shouldNotify = FileUtils::getInstance()->isPopupNotify();
    FileUtils::getInstance()->setPopupNotify(false);
    
#if VERBOSE_PERFORMANCE_TIME
    timeval startTime;
    gettimeofday(&startTime, NULL);
#endif
    std::string filePath = ScreateF("%s%s.ccbi", file, isPhone ? "-phone" : "")->getCString();
    CCLOG("Filepath : %s", filePath.c_str());
    FileUtils::getInstance()->setPopupNotify(shouldNotify);
    Node* myNode = NULL;
    if(FileUtils::getInstance()->isFileExist(filePath))
    {
        CCLOG("File exist");
        myNode = ccbReader->readNodeGraphFromFile(filePath.c_str());
    }
    else if(isPhone)
    {
        myNode = ccbReader->readNodeGraphFromFile(ScreateF("%s.ccbi", file)->getCString());
    }
    
#if VERBOSE_PERFORMANCE_TIME
    timeval middleTime;
    gettimeofday(&middleTime, NULL);
    CCLOG("CCBReader loaded file %s in %f ms", file, getTimeDifferenceMS(startTime, middleTime));
#endif
    
    //Despite cocosbuilder saying so, Label and Node (for Panel) aren't resized properly, so there it is
    /*Size frameSize = Director::getInstance()->getWinSize();
     float scaleX = (float)frameSize.width / designResolutionSize.width;
     float scaleY = (float)frameSize.height / designResolutionSize.height;
     float scale = MAX(scaleX, scaleY);
     float minScale = MIN(scaleX, scaleY);
     CCLOG("min : %f, max : %f, loading : %f", minScale, scale, _loadingScale);*/
    float usedScale = _loadingScale;
    
    //this code is dubious at best .... refactor it later
#if VERBOSE_LOAD_CCB
    CCLOG("ccb file %s loaded, doing rescaling ...", file);
#endif
    for(auto node : myNode->getChildren())
    {
        //Note : Panels are never tested against isKindOfClass because :
        //against Node, all nodes return true
        //against CustomNode, a tagging is required on cocosBuilder
        
        //Depth 0 of nesting
        if(isKindOfClass(node, Label))
        {
            Label* label = (Label*)node;
#if VERBOSE_LOAD_CCB
            CCLOG("label font : %s", label->getSystemFontName().c_str());
#endif
            label->setSystemFontSize(label->getSystemFontSize() * usedScale);
            /*TTFConfig newConfig = label->getTTFConfig();
            newConfig.fontSize *= usedScale;
            label->setTTFConfig(newConfig);*/
        }
        else if(isKindOfClass(node, CustomInput))
        {
            
        }
        else if(isKindOfClass(node, Sprite) || isKindOfClass(node, ui::Scale9Sprite))
        {
            
        }
        else if(!node->getChildren().empty())//Panel
        {
            node->setScaleX(node->getScaleX()*usedScale);
            node->setScaleY(node->getScaleY()*usedScale);
            Node* parentNode = node;
            
            for(auto nodeChild : node->getChildren())
            {
                //Depth 1 is a special case too, because nodes don't have to be moved and the scale is not calculated the same way
                if(isKindOfClass(nodeChild, Label))
                {
                    Label* label = (Label*)nodeChild;
                    label->setScale(label->getScale() / parentNode->getScale());
                    label->setSystemFontSize(label->getSystemFontSize() * parentNode->getScale());
                    /*TTFConfig newConfig = label->getTTFConfig();
                    newConfig.fontSize *= parentNode->getScale();
                    label->setTTFConfig(newConfig);*/
#if VERBOSE_LOAD_CCB
                    CCLOG("label font : %s, size : %f, scale : %f, parent node scale : %f, dimensions : %f, %f, depth 1", label->getSystemFontName().c_str(), label->getSystemFontSize(), label->getScale(), parentNode->getScale(), label->getDimensions().width, label->getDimensions().height);
#endif
                }
                else if(isKindOfClass(nodeChild, CustomInput))
                {
                    //input->setFontSize((float)input->getFontSize() / usedScale);
                    //input->setPreferredSize(Size(input->getPreferredSize().width / usedScale, input->getPreferredSize().height / usedScale));
                    //input->setFontSize((float)input->getFontSize() * parentNode->getScale());
#if VERBOSE_LOAD_CCB
                    CustomInput* input = (CustomInput*)nodeChild;
                    CCLOG("input font size : %d, parent node scale : %f, dimensions : %f, %f, depth 1", input->getFontSize() , parentNode->getScale(), input->getPreferredSize().width, input->getPreferredSize().height);
#endif
                }
                else if(isKindOfClass(nodeChild, Sprite))
                {
                    nodeChild->setScaleX(nodeChild->getScaleX() / usedScale);
                    nodeChild->setScaleY(nodeChild->getScaleY() / usedScale);
                }
                else if(isKindOfClass(nodeChild, ui::Scale9Sprite))
                {
                    nodeChild->setScaleX(nodeChild->getScaleX() / usedScale);
                    nodeChild->setScaleY(nodeChild->getScaleY() / usedScale);
                    nodeChild->setContentSize(SizeMult(nodeChild->getContentSize(), usedScale));
                }
                else if(!nodeChild->getChildren().empty())//Panel
                {
                    nodeChild->setScaleX(nodeChild->getScaleX() / usedScale);
                    nodeChild->setScaleY(nodeChild->getScaleY() / usedScale);
                    nodeChild->setContentSize(SizeMult(nodeChild->getContentSize(), usedScale));
                    //For depth 2 and more, the algorithm is the same
                    resizeChildren(parentNode, nodeChild, usedScale, 2);
                }
            }
        }
    }
    
    Panel* parent = NULL;
    if(inPanel != NULL)
    {
        myNode->setContentSize(Size(0, 0));
        parent = GraphicLayer::sharedLayer()->createPanelWithNode(inPanel, myNode, zIndex);
    }
    
    loadNodeToFenneX(myNode, parent);
    reorderZindex();
    linkInputLabels();
    
    animManagers.push_back(ccbReader->getAnimationManager());
    
    ccbReader->release();
    
#if VERBOSE_PERFORMANCE_TIME
    timeval endTime;
    gettimeofday(&endTime, NULL);
    CCLOG("Node %s loaded to FenneX in %f ms, total with load file : %f ms", file, getTimeDifferenceMS(middleTime, endTime), getTimeDifferenceMS(startTime, endTime));
#endif
    return parent;
}