axmol/samples/Cpp/TestCpp/Classes/ExtensionsTest/CocoStudioSceneTest/SceneEditorTest.cpp

113 lines
2.9 KiB
C++
Raw Normal View History

2013-09-10 09:53:15 +08:00
#include "cocos-ext.h"
#include "../ExtensionsTest.h"
#include "SceneEditorTest.h"
using namespace cocos2d;
using namespace cocos2d::extension;
SceneEditorTestLayer::~SceneEditorTestLayer()
{
}
SceneEditorTestLayer::SceneEditorTestLayer()
{
2013-09-10 11:02:50 +08:00
_curNode = NULL;
2013-09-10 09:53:15 +08:00
}
Scene* SceneEditorTestLayer::scene()
{
Scene * scene = NULL;
do
{
// 'scene' is an autorelease object
scene = Scene::create();
CC_BREAK_IF(! scene);
// 'layer' is an autorelease object
SceneEditorTestLayer *layer = SceneEditorTestLayer::create();
CC_BREAK_IF(! layer);
// add layer as a child to scene
scene->addChild(layer);
} while (0);
// return the scene
return scene;
}
// on "init" you need to initialize your instance
bool SceneEditorTestLayer::init()
{
bool bRet = false;
do
{
2013-09-10 11:02:50 +08:00
CC_BREAK_IF(! LayerColor::initWithColor(Color4B(0,0,0,255)));
2013-09-10 09:53:15 +08:00
Node *root = createGameScene();
CC_BREAK_IF(!root);
this->addChild(root, 0, 1);
bRet = true;
} while (0);
return bRet;
}
2013-09-10 11:02:50 +08:00
cocos2d::Node* SceneEditorTestLayer::createGameScene()
2013-09-10 09:53:15 +08:00
{
2013-09-10 11:02:50 +08:00
Node *pNode = SceneReader::getInstance()->createNodeWithSceneFile("scenetest/FishJoy2.json");
2013-09-10 09:53:15 +08:00
if (pNode == NULL)
{
return NULL;
}
2013-09-10 11:02:50 +08:00
_curNode = pNode;
2013-09-10 09:53:15 +08:00
//fishes
/*cocos2d::extension::armature::Armature *pBlowFish = getFish(10008, "blowFish");
cocos2d::extension::armature::Armature *pButterFlyFish = getFish(10009, "butterFlyFish");
pBlowFish->getAnimation()->playByIndex(0);
pButterFlyFish->getAnimation()->playByIndex(0);*/
2013-09-10 11:02:50 +08:00
MenuItemFont *itemBack = MenuItemFont::create("Back", CC_CALLBACK_1(SceneEditorTestLayer::toExtensionsMainLayer, this));
itemBack->setColor(Color3B(255, 255, 255));
itemBack->setPosition(Point(VisibleRect::rightBottom().x - 50, VisibleRect::rightBottom().y + 25));
Menu *menuBack = Menu::create(itemBack, NULL);
menuBack->setPosition(Point(0.0f, 0.0f));
2013-09-10 09:53:15 +08:00
menuBack->setZOrder(4);
pNode->addChild(menuBack);
//ui action
//cocos2d::extension::UIActionManager::shareManager()->PlayActionByName("startMenu_1.json","Animation1");
return pNode;
}
2013-09-10 11:02:50 +08:00
void SceneEditorTestLayer::toExtensionsMainLayer(cocos2d::Object *sender)
2013-09-10 09:53:15 +08:00
{
2013-09-10 11:02:50 +08:00
ComAudio *pBackMusic = (ComAudio*)(_curNode->getComponent("CCBackgroundAudio"));
pBackMusic->stopBackgroundMusic();
2013-09-10 09:53:15 +08:00
ExtensionsTestScene *pScene = new ExtensionsTestScene();
pScene->runThisTest();
pScene->release();
2013-09-10 11:02:50 +08:00
}
2013-09-10 09:53:15 +08:00
cocos2d::extension::armature::Armature* SceneEditorTestLayer::getFish(int nTag, const char *pszName)
{
2013-09-10 11:02:50 +08:00
if (_curNode == NULL)
2013-09-10 09:53:15 +08:00
{
return NULL;
}
2013-09-10 11:02:50 +08:00
ComRender *pFishRender = (ComRender*)(_curNode->getChildByTag(nTag)->getComponent(pszName));
2013-09-10 09:53:15 +08:00
return (cocos2d::extension::armature::Armature *)(pFishRender->getNode());
}
2013-09-10 11:02:50 +08:00
void runSceneEditorTestLayer()
{
Scene *pScene = SceneEditorTestLayer::scene();
Director::getInstance()->replaceScene(pScene);
}