cocos2d::CCNode* SceneEditorTestLayer::createGameScene() { CCNode *pNode = CCJsonReader::sharedJsonReader()->createNodeWithJsonFile("FishJoy2.json"); if (pNode == NULL) { return NULL; } m_pCurNode = pNode; //play back music CCComAudio *pAudio = (CCComAudio*)(pNode->getComponent("Audio")); pAudio->playBackgroundMusic(pAudio->getFile(), pAudio->getIsLoop()); //fishes CCArmature *pBlowFish = getFish(5, "blowFish"); CCArmature *pButterFlyFish = getFish(6, "butterFlyFish"); pBlowFish->getAnimation()->playByIndex(0); pButterFlyFish->getAnimation()->playByIndex(0); CCMenuItemFont *itemBack = CCMenuItemFont::create("Back", this, menu_selector(SceneEditorTestLayer::toExtensionsMainLayer)); itemBack->setColor(ccc3(255, 255, 255)); itemBack->setPosition(ccp(VisibleRect::rightBottom().x - 50, VisibleRect::rightBottom().y + 25)); CCMenu *menuBack = CCMenu::create(itemBack, NULL); menuBack->setPosition(CCPointZero); menuBack->setZOrder(4); pNode->addChild(menuBack); //ui action cocos2d::extension::UIActionManager::shareManager()->PlayActionByName("startMenu_1.json","Animation1"); return pNode; }
// on "init" you need to initialize your instance bool HelloWorld::init() { ////////////////////////////// // 1. super init first if ( !CCLayer::init() ) { return false; } CCSize visibleSize = CCDirector::sharedDirector()->getVisibleSize(); CCPoint origin = CCDirector::sharedDirector()->getVisibleOrigin(); ///////////////////////////// // 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::create( "CloseNormal.png", "CloseSelected.png", this, menu_selector(HelloWorld::menuCloseCallback)); pCloseItem->setPosition(ccp(origin.x + visibleSize.width - pCloseItem->getContentSize().width/2 , origin.y + pCloseItem->getContentSize().height/2)); // create menu, it's an autorelease object CCMenu* pMenu = CCMenu::create(pCloseItem, NULL); pMenu->setPosition(CCPointZero); this->addChild(pMenu, 1); ///////////////////////////// // 3. add your codes below... CCNode* gameScene = SceneReader::sharedSceneReader()->createNodeWithSceneFile("DemoCowboy.json"); addChild(gameScene); //Create player CCNode* playerNode = gameScene->getChildByTag(10004); player = new Player(playerNode); //Assign callbacks to the buttons CCNode* uiNode = gameScene->getChildByTag(10005); UILayer* ui = (UILayer*)uiNode->getComponent("GUIComponent")->getNode(); UIButton* btnLeft = (UIButton*)ui->getWidgetByName("LeftButton"); btnLeft->addTouchEventListener(this, toucheventselector(HelloWorld::onMoveLeft)); UIButton* btnRight = (UIButton*)ui->getWidgetByName("RightButton"); btnRight->addTouchEventListener(this, toucheventselector(HelloWorld::onMoveRight)); UIButton* btnFire = (UIButton*)ui->getWidgetByName("FireButton"); // btnFire->addReleaseEvent(this, coco_releaseselector(HelloWorld::onFire)); btnFire->addTouchEventListener(this, toucheventselector(HelloWorld::onFire)); //Enable update loop this->scheduleUpdate(); return true; }
void ArmatureActionState::removeAll() { do { CCNode *pNode = SceneReader::sharedSceneReader()->getNodeByTag(_nTag); CC_BREAK_IF(pNode == NULL); CCComRender *pRender = (CCComRender*)(pNode->getComponent(_ComName.c_str())); CC_BREAK_IF(pRender == NULL); CCArmature *pAr = (CCArmature *)(pRender->getNode()); CC_BREAK_IF(pAr == NULL); TriggerMng::sharedTriggerMng()->removeArmatureMovementCallBack(pAr, this, movementEvent_selector(ArmatureActionState::animationEvent)); } while (0); }
void ArmaturePlayAction::done() { do { CCNode *pNode = SceneReader::sharedSceneReader()->getNodeByTag(_nTag); CC_BREAK_IF(pNode == NULL); CCComRender *pRender = (CCComRender*)(pNode->getComponent(_comName.c_str())); CC_BREAK_IF(pRender == NULL); CCArmature *pAr = (CCArmature *)(pRender->getNode()); CC_BREAK_IF(pAr == NULL); pAr->getAnimation()->play(_aniname.c_str()); } while (0); }
bool ArmatureActionState::init() { do { CCNode *pNode = SceneReader::sharedSceneReader()->getNodeByTag(_nTag); CC_BREAK_IF(pNode == NULL); CCComRender *pRender = (CCComRender*)(pNode->getComponent(_comName.c_str())); CC_BREAK_IF(pRender == NULL); CCArmature *pAr = (CCArmature *)(pRender->getNode()); CC_BREAK_IF(pAr == NULL); TriggerMng::getInstance()->addArmatureMovementCallBack(pAr, this, movementEvent_selector(ArmatureActionState::animationEvent)); } while (0); return true; }
void PlayMusic::done() { do { CCNode *pNode = SceneReader::sharedSceneReader()->getNodeByTag(_nTag); CC_BREAK_IF(pNode == NULL); CCComAudio *audio = (CCComAudio*)(pNode->getComponent(_comName.c_str())); CC_BREAK_IF(audio == NULL); if (_nType == 0) { audio->playBackgroundMusic(); } else if (_nType == 1) { audio->playEffect(); } } while (0); }