bool CSpriteObject::changeState(const string& s, CComponentParameter* parameter, bool force)
{
    if (!CVisibleObject::changeState(s, parameter, force))
    {
        return false;
    }
    
    if (s.empty())
    {
        getInnerSprite()->stopAllActions();
    }
    else
    {
        if (getCCBReader())
        {
            CCBAnimationManager* am = getCCBReader()->getAnimationManager();
            CCArray* seq = am->getSequences();
            CCObject* pObj;
            CCARRAY_FOREACH(seq, pObj)
            {
                CCBSequence *seq = (CCBSequence*)pObj;
                if (s.compare(seq->getName()) == 0)
                {
                    am->runAnimations(seq->getSequenceId(), 0);
                }
            }
//            getCCBReader()->getAnimationManager()->runAnimations(s.c_str());
        }
    }
FMMapAvatarNode * FMMapAvatarNode::creatAvatarNode(bool includeSelf, CCDictionary * dic)
{
    FMMapAvatarNode * node = new FMMapAvatarNode();
    if (node) {
        FMDataManager * manager = FMDataManager::sharedManager();
        
        node->m_includeSelf = includeSelf;
        node->m_dicList->addObject(dic);
        
        if (includeSelf) {
            CCBAnimationManager * anim = (CCBAnimationManager *)node->m_mainAvatarNode->getUserObject();
            anim->runAnimationsForSequenceNamed("2");
            node->m_mainAvatarNode->setPosition(ccp(avatarDiffx, avatarDiffy));
        }
        
        CCString * uid = (CCString *)dic->objectForKey("uid");
        const char * iconpath = SNSFunction_getFacebookIcon(uid->getCString());

        CCSprite * icon = (CCSprite*)node->m_mainAvatarNode->getChildByTag(1);
        
        if (iconpath && manager->isFileExist(iconpath)) {
            CCSprite * spr = CCSprite::create(iconpath);
            float size = 26.f;
            spr->setScale(size / MAX(spr->getContentSize().width, size));
            icon->addChild(spr);
            spr->setPosition(ccp(icon->getContentSize().width/2, icon->getContentSize().height/2));
        }
        
        node->autorelease();
        return node;
    }
    CC_SAFE_DELETE(node);
    return NULL;
}
CCNode* CCBReader::readNodeGraphFromFile(const char *pCCBFileName, CCObject *pOwner, const CCSize &parentSize)
{
    if (NULL == pCCBFileName || strlen(pCCBFileName) == 0)
    {
        return NULL;
    }

    std::string strCCBFileName(pCCBFileName);
    std::string strSuffix(".ccbi");
    // Add ccbi suffix
    if (!CCBReader::endsWith(strCCBFileName.c_str(), strSuffix.c_str()))
    {
        strCCBFileName += strSuffix;
    }

    std::string strPath = CCFileUtils::sharedFileUtils()->fullPathForFilename(strCCBFileName.c_str());
    unsigned long size = 0;

    unsigned char * pBytes = CCFileUtils::sharedFileUtils()->getFileData(strPath.c_str(), "rb", &size);
    CCData *data = new CCData(pBytes, size);
    CC_SAFE_DELETE_ARRAY(pBytes);

    CCNode *ret =  this->readNodeGraphFromData(data, pOwner, parentSize);
    
    data->release();

	// (jason_shi): 将未命名的JSController命名为路径名
	CCBAnimationManager* animMgr = (CCBAnimationManager*)ret->getUserObject();
	std::string controllerName = animMgr->getDocumentControllerName();
	if (controllerName.compare("") == 0)
	{
		animMgr->setDocumentControllerName(pCCBFileName);
	}
    return ret;
}
void Explosion::onNodeLoaded(cocos2d::CCNode * pNode, cocos2d::extension::CCNodeLoader * pNodeLoader)
{
  CCBAnimationManager* animationManager = dynamic_cast<CCBAnimationManager*>(this->getUserObject());
  if (animationManager) {
    animationManager->setDelegate(this);
  }
}
Beispiel #5
0
void Enemy::handleCollisionWith(GameObject* gameObject)
{
//    if (this->hp<=0) {
//        this->isScheduledForRemove = true;
//    }
//    
//    bloodBar->setScaleX(0.3f*hp/maxHp);
//    
    if (gameObject != NULL)
    {
        if (gameObject->getTag() < 200)
        {
            if (stopAction())
            {
                return;
            }
            if (checkIsCollision(gameObject))
            {
                isCollision = true;
                stop();
                CCBAnimationManager* animationManager = dynamic_cast<CCBAnimationManager*>(this->getUserObject());
                
                if (animationManager->getRunningSequenceName() == NULL or strcmp(animationManager->getRunningSequenceName(), "attack") != false)
                {
                    animationManager->runAnimationsForSequenceNamed("attack");
                    CocosDenshion::SimpleAudioEngine::sharedEngine()->playEffect(effectSoundFileName);
                    gameObject->atkHandler(atk, this);
                }
                curActionCount++;
            }
        }
        
    }    
}
Beispiel #6
0
void SinglePlayerScene::onEnter()
{
    cocos2d::Node::onEnter();

    CCBAnimationManager *animationManager = dynamic_cast<CCBAnimationManager*>(this->getUserObject());
    animationManager->setDelegate(this);

    setKeyboardEnabled(true);

    if (!m_enterred)
    {
        _playerSprite->setSpriteFrame(StringUtils::format("%ssteady.png", m_framePrefix.c_str()));
        auto bg = Director::getInstance()->getTextureCache()->addImage(m_game->getBackground());
        _background->setTexture(bg);

        this->setupPhysics();

        this->setupListeners();

        if (!m_game->isPracticeMode())
        {
            m_game->getPlayer()->addPlays(1);
        }
    }

    m_enterred = true;
}
void ShopDialogEntry::onEnter()
{
	cocos2d::Node::onEnter();

	CCBAnimationManager *animationManager = dynamic_cast<CCBAnimationManager*>(this->getUserObject());
	animationManager->setDelegate(this);
}
Beispiel #8
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;
}
void HowToPlayScene::onExit()
{
	cocos2d::Node::onExit();

	CCBAnimationManager *animationManager = dynamic_cast<CCBAnimationManager*>(this->getUserObject());
	animationManager->setDelegate(NULL);

}
Beispiel #10
0
void ComicsScene::onExit()
{
	cocos2d::Layer::onExit();

	CCBAnimationManager *animationManager = dynamic_cast<CCBAnimationManager*>(this->getUserObject());
	animationManager->setDelegate(NULL);

}
Beispiel #11
0
void AboutMenu::onExit()
{
	cocos2d::Node::onExit();

	CCBAnimationManager *animationManager = dynamic_cast<CCBAnimationManager*>(this->getUserObject());
	animationManager->setDelegate(NULL);

    UI_LOCK_MANAGER_DECREASE();
}
Beispiel #12
0
void SinglePlayerScene::onExit()
{
    cocos2d::Node::onExit();

    CCBAnimationManager *animationManager = dynamic_cast<CCBAnimationManager*>(this->getUserObject());
    animationManager->setDelegate(NULL);

    UNOBSERVE(this);
}
Beispiel #13
0
void BasicPanel::PlayCCBAction(const char* pszActionName, float nDelayTime)
{
	CCBAnimationManager* pManager	= dynamic_cast<CCBAnimationManager*>(this->getUserObject());
	XY_FAILED_JUMP(pManager);

	pManager->runAnimationsForSequenceNamedTweenDuration(pszActionName, nDelayTime);
Exit0:
	return;
}
Beispiel #14
0
void Enemy::resetSpeed()
{
    xSpeed = kCJStartSpeed;
    CCBAnimationManager* animationManager = dynamic_cast<CCBAnimationManager*>(this->getUserObject());
    if (animationManager->getRunningSequenceName() == NULL or strcmp(animationManager->getRunningSequenceName(), "walk") != false)
    {
        animationManager->runAnimationsForSequenceNamed("walk");
    }
}
Beispiel #15
0
void  Soldier::normalAtkHandler(GameObject* gameObject)
{
    CCBAnimationManager* animationManager = dynamic_cast<CCBAnimationManager*>(this->getUserObject());
    if (animationManager->getRunningSequenceName() == NULL or strcmp(animationManager->getRunningSequenceName(), "attack1") != false)
    {
        animationManager->runAnimationsForSequenceNamed("attack1");
        CocosDenshion::SimpleAudioEngine::sharedEngine()->playEffect(effectSoundFileName);
        gameObject->atkHandler(atk, this);
    }
}
Beispiel #16
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 SettingsDialog::onEnter()
{
	cocos2d::Node::onEnter();

	CCBAnimationManager *animationManager = dynamic_cast<CCBAnimationManager*>(this->getUserObject());
	animationManager->setDelegate(this);

	this->setKeyboardEnabled(true);
    
    UI_LOCK_MANAGER_INCREASE();
}
Beispiel #18
0
int BasicPanel::LuaRemoveAnimationDelegate(lua_State *L)
{
    CCBAnimationManager* pManager = NULL;
    
    XYLOG_FAILED_JUMP(lua_gettop(L) == 0);
    
    pManager = dynamic_cast<CCBAnimationManager*>(this->getUserObject());
    pManager->setDelegate(NULL);
Exit0:
    return 0;
}
Beispiel #19
0
void XCCBReader::pause()
{
	CCBAnimationManager* mActionManager = getAnimationManager();
	mActionManager->getRootNode()->pauseSchedulerAndActions();

	CCDictionary* pDic = mActionManager->getNodeSequences();
	CCDictElement* pElement = NULL;
	CCDICT_FOREACH(pDic, pElement)
	{
		CCNode *node = (CCNode*)pElement->getIntKey();
		node->pauseSchedulerAndActions();
	}
Beispiel #20
0
bool CCBReader::init()
{
    // Setup action manager
    CCBAnimationManager *pActionManager = new (std::nothrow) CCBAnimationManager();
    setAnimationManager(pActionManager);
    pActionManager->release();

    // Setup resolution scale and container size
    _animationManager->setRootContainerSize(Director::DirectorInstance->getWinSize());

    return true;
}
Beispiel #21
0
bool CCBReader::init()
{
    // Setup action manager
    CCBAnimationManager *pActionManager = new CCBAnimationManager();
    setAnimationManager(pActionManager);
    pActionManager->release();
    
    // Setup resolution scale and container size
    mActionManager->setRootContainerSize(CCDirector::sharedDirector()->getWinSize());
    
    return true;
}
static int tolua_cocos2d_CCBAnimationManager_setCallFuncForLuaCallbackNamed(lua_State* tolua_S)
{
    if (nullptr == tolua_S)
        return 0;
    
    int argc = 0;
    CCBAnimationManager* self = nullptr;
    
#if COCOS2D_DEBUG >= 1
    tolua_Error tolua_err;
	if (!tolua_isusertype(tolua_S,1,"cc.CCBAnimationManager",0,&tolua_err)) goto tolua_lerror;
#endif
    
    self = static_cast<CCBAnimationManager*>(tolua_tousertype(tolua_S,1,0));
#if COCOS2D_DEBUG >= 1
	if (nullptr == self) {
		tolua_error(tolua_S,"invalid 'self' in function 'tolua_cocos2d_CCBAnimationManager_setCallFuncForLuaCallbackNamed'\n", NULL);
		return 0;
	}
#endif
    
    argc = lua_gettop(tolua_S) - 1;
    
    if (2 == argc)
    {
        
#if COCOS2D_DEBUG >= 1
        if (!tolua_isusertype(tolua_S,2, "cc.CallFunc", 0, &tolua_err) ||
            !tolua_isstring(tolua_S, 3, 0, &tolua_err) )
            goto tolua_lerror;
#endif
        
        CallFunc* pCallFunc = static_cast<CallFunc*>(tolua_tousertype(tolua_S,2,0));
        const char* keyframeCallback = ((const char*)  tolua_tostring(tolua_S,3,0));
        std::string strKey = "";
        if (NULL != keyframeCallback) {
            strKey = keyframeCallback;
        }
        self->setCallFunc(pCallFunc, strKey);
        
        return 0;
    }
    
    CCLOG("'setCallFuncForLuaCallbackNamed' function of CCBAnimationManager  has wrong number of arguments: %d, was expecting %d\n", argc, 1);
    return 0;
    
#if COCOS2D_DEBUG >= 1
tolua_lerror:
    tolua_error(tolua_S,"#ferror in function 'setCallFuncForLuaCallbackNamed'.",&tolua_err);
    return 0;
#endif
}
void HowToPlayScene::onEnter()
{
	cocos2d::Node::onEnter();

	CCBAnimationManager *animationManager = dynamic_cast<CCBAnimationManager*>(this->getUserObject());
	animationManager->setDelegate(this);

	this->setKeyboardEnabled(true);
    
    m_currentPage = 0;
    
    this->fixArrows();
}
Beispiel #24
0
CCNode* CCBReader::readNodeGraphFromData(CCData *pData, CCObject *pOwner, const CCSize &parentSize)
{
    mData = pData;
    CC_SAFE_RETAIN(mData);
    mBytes = mData->getBytes();
    mCurrentByte = 0;
    mCurrentBit = 0;
    mOwner = pOwner;
    CC_SAFE_RETAIN(mOwner);

    mActionManager->setRootContainerSize(parentSize);
    mActionManager->mOwner = mOwner;  
    
    CCDictionary* animationManagers = CCDictionary::create();
    CCNode *pNodeGraph = readFileWithCleanUp(true, animationManagers);
    
    if (pNodeGraph && mActionManager->getAutoPlaySequenceId() != -1 && !jsControlled)
    {
        // Auto play animations
        mActionManager->runAnimationsForSequenceIdTweenDuration(mActionManager->getAutoPlaySequenceId(), 0);
    }
    // Assign actionManagers to userObject
    if(jsControlled) {
        mNodesWithAnimationManagers = new CCArray();
        mAnimationManagersForNodes = new CCArray();
    }
    
    CCDictElement* pElement = NULL;
    CCDICT_FOREACH(animationManagers, pElement)
    {
        CCNode* pNode = (CCNode*)pElement->getIntKey();
        CCBAnimationManager* manager = (CCBAnimationManager*)animationManagers->objectForKey((intptr_t)pNode);
		// (jason_shi): 将未命名的JSController命名为路径名
		if (manager->getDocumentControllerName().compare("") == 0)
		{
			CCString* pStr = dynamic_cast<CCString*>(pNode->getCustObject());
			if (pStr)
			{
				manager->setDocumentControllerName(pStr->getCString());
				pNode->setCustObject(nullptr);
			}
		}

        pNode->setUserObject(manager);

        if (jsControlled)
        {
            mNodesWithAnimationManagers->addObject(pNode);
            mAnimationManagersForNodes->addObject(manager);
        }
    }
Beispiel #25
0
void ComicsScene::onEnter()
{
	cocos2d::Layer::onEnter();

	CCBAnimationManager *animationManager = dynamic_cast<CCBAnimationManager*>(this->getUserObject());
	animationManager->setDelegate(this);

	this->setKeyboardEnabled(true);

    if (IS_SOUND_ENABLED)
    {
    	PLAY_SOUND("pageflip.mp3");
    }
}
Beispiel #26
0
void Zombie::handleCollisionWith(GameObject* gameObject)
{
    if (this->hp<=0) {
        this->isScheduledForRemove = true;
    }
    S1* rabit = dynamic_cast<S1*>(gameObject);


    if (rabit != NULL) {
        xSpeed = 0;
        rabit->setHp(rabit->getHp()-this->atk);
        CCBAnimationManager* animationManager = dynamic_cast<CCBAnimationManager*>(this->getUserObject());
        animationManager->runAnimationsForSequenceNamed("attack");
    }
}
Beispiel #27
0
bool CCBReader::init()
{
    mOwnerOutletNodes = new CCArray();
    mOwnerCallbackNodes = new CCArray();
    mOwnerOwnerCallbackControlEvents = new CCArray();
    // Setup action manager
    CCBAnimationManager *pActionManager = new CCBAnimationManager();
    setAnimationManager(pActionManager);
    pActionManager->release();
    
    // Setup resolution scale and container size
    mActionManager->setRootContainerSize(CCDirector::sharedDirector()->getWinSize());
    
    return true;
}
bool FMMapAvatarNode::addAvatarNode(CCDictionary * dic)
{
    if (m_avatarList->count() >= 4) {
        return false;
    }
    FMDataManager * manager = FMDataManager::sharedManager();
    
    FMMainScene * mainScene = (FMMainScene *)FMDataManager::sharedManager()->getUI(kUI_MainScene);
    FMWorldMapNode* wd = (FMWorldMapNode*)mainScene->getNode(kWorldMapNode);
    CCNode * n = manager->createNode("UI/FMUIAvatar.ccbi", wd);
    addChild(n,10-m_avatarList->count(),m_avatarList->count());
    m_avatarList->addObject(n);
    
    CCString * uid = (CCString *)dic->objectForKey("uid");
    const char * iconpath = SNSFunction_getFacebookIcon(uid->getCString());
    
    CCSprite * icon = (CCSprite*)n->getChildByTag(1);
    
    if (iconpath && manager->isFileExist(iconpath)) {
        CCSprite * spr = CCSprite::create(iconpath);
        float size = 26.f;
        spr->setScale(size / MAX(spr->getContentSize().width, size));
        icon->addChild(spr);
        spr->setPosition(ccp(icon->getContentSize().width/2, icon->getContentSize().height/2));
    }
    
    int cnt = m_avatarList->count()-1;
    if (m_includeSelf) {
        cnt++;
    }
    n->setPosition(ccp(cnt * avatarDiffx, cnt * avatarDiffy));
    
    CCBAnimationManager * anim = (CCBAnimationManager *)n->getUserObject();
    anim->runAnimationsForSequenceNamed("2");

    m_dicList->addObject(dic);
    
    return true;
}
Beispiel #29
0
void Dragon::handleCollisionWith(GameObject* gameObject)
{
  Coin *coin = dynamic_cast<Coin*>(gameObject);
  Bomb *bomb = dynamic_cast<Bomb*>(gameObject);
  if (coin)
  {
    // Took a coin
    ySpeed_ = kCJCoinSpeed;
    
    GameScene::sharedScene()->setScore(GameScene::sharedScene()->getScore()+1);
  }
  else if (bomb)
  {
    // Hit a bomb
    if (ySpeed_ > 0) ySpeed_ = 0;
    
    CCBAnimationManager* animationManager = dynamic_cast<CCBAnimationManager*>(this->getUserObject());
    if (animationManager) {
      animationManager->runAnimationsForSequenceNamed("Hit");
    }
  }
  
}
Beispiel #30
0
void Hero::handleCollisionWith(GameObject *gameObject)
{
    CCBAnimationManager* animationManager = dynamic_cast<CCBAnimationManager*>(this->getUserObject());
    animationManager->runAnimationsForSequenceNamed("attack");
}