void HelloWorld::update(float delta) { if(m_bStart) { CCArmature *pHero = (CCArmature*)(m_pGameScene->getChildByTag(10005)->getComponent("CCArmature")->getNode()); pHero->getParent()->setPositionX(pHero->getParent()->getPositionX() + m_fSpeed); CCArmature *pEnemy = (CCArmature*)(m_pGameScene->getChildByTag(10006)->getComponent("CCArmature")->getNode()); if(ccpDistance(ccp(pHero->getParent()->getPositionX(), 0), ccp(pEnemy->getParent()->getPositionX(), 0)) < m_fAttackDis) { pHero->getAnimation()->play("attack"); pHero->getAnimation()->setMovementEventCallFunc(this, movementEvent_selector(HelloWorld::animationEvent)); m_bStart = false; } } if(m_bDead) { CCComRender *pUIRender = static_cast<CCComRender*>(m_pGameScene->getChildByTag(10007)->getComponent("GUIComponent")); UILayer *pUILayer = static_cast<UILayer*>(pUIRender->getNode()); UILoadingBar *pHPLoadingBar = static_cast<UILoadingBar*>(pUILayer->getWidgetByName("hp02_LoadingBar")); UILoadingBar *pMPLoadingBar = static_cast<UILoadingBar*>(pUILayer->getWidgetByName("mp02_LoadingBar")); pHPLoadingBar->setPercent(m_fPercentage); pMPLoadingBar->setPercent(m_fPercentage); m_fPercentage -= 2.0f; if (m_fPercentage < 0.0f) { unscheduleUpdate(); } } }
void SceneRender::comCallBack(cocos2d::CCObject *tar, void *dict) { if (dict == NULL || tar == NULL) { return; } CCArmature *pAr = dynamic_cast<CCArmature*>(tar); if (pAr == NULL) { return; } rapidjson::Value *v = (rapidjson::Value *)dict; bool isShowColliderRect = DICTOOL->getBooleanValue_json(*v, "isShowColliderRect"); if (isShowColliderRect == false) { return; } ColliderRectDrawer *drawer = ColliderRectDrawer::create(pAr); if (pAr->getParent()) { pAr->getParent()->addChild(drawer); } drawer->setVisible(true); }