加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 百科 > 正文

cocos2dx 代码使用cocoStudio 生成的场景json文件

发布时间:2020-12-14 16:53:02 所属栏目:百科 来源:网络整理
导读:摘要 : 正在学习使用cocoStudio开发cocos2dx程序,好不容易用编辑器做好的界面,在代码里不会用了不过在cocos2dx的源码例子TestCpp中提供了例子,在这里记录下方便以后学习,懒的用必记录了我在这里看的源码是cocos2dx2.2.2 ... 正在学习使用cocoStudio开发c

摘要: 正在学习使用cocoStudio开发cocos2dx程序,好不容易用编辑器做好的界面,在代码里不会用了不过在cocos2dx的源码例子TestCpp中提供了例子,在这里记录下方便以后学习,懒的用必记录了我在这里看的源码是cocos2dx2.2.2 ...

正在学习使用cocoStudio开发cocos2dx程序,好不容易用编辑器做好的界面,在代码里不会用了

不过在cocos2dx的源码例子TestCpp中提供了例子,在这里记录下方便以后学习,懒的用必记录了

我在这里看的源码是cocos2dx2.2.2

在TestCpp 的例子中,有各ExtensionsTest,然后CocosStudioSceneTest 里面就可以看到好多不同的场景了,进去是捕鱼达人的界面,但点开始游戏没有反映,所以我调了一个能控制游戏的例子 UI Component Test



进去是背景,2各动画,一个按钮

下面找到对应的控制代码cocos2d-x-2.2.2samplesCppTestCppClassesExtensionsTestCocoStudioSceneTest 下面的

SceneEdiotrTest.h 找到这个类,就是控制这个scene的

[cpp] view plaincopy在CODE上查看代码片派生到我的代码片
class UIComponentTest : public SceneEditorTestLayer
{
public:
UIComponentTest();
~UIComponentTest();

virtual std::string title();
virtual void onEnter();
virtual void onExit();
cocos2d::CCNode* createGameScene();
void touchEvent(CCObject *pSender,cocos2d::gui::TouchEventType type);
private:
cocos2d::CCNode* _node;
};
SceneEdiotrTest.cpp

[cpp] view plaincopy在CODE上查看代码片派生到我的代码片
UIComponentTest::UIComponentTest()
: _node(NULL)
{

}

UIComponentTest::~UIComponentTest()
{
}

std::string UIComponentTest::title()
{
return "UI Component Test";
}

void UIComponentTest::onEnter()
{
SceneEditorTestLayer::onEnter();
do
{
CCNode *root = createGameScene();
CC_BREAK_IF(!root);
this->addChild(root,1);
} while (0);
}

void UIComponentTest::onExit()
{
CCArmatureDataManager::purge();
SceneReader::purge();
ActionManager::purge();
GUIReader::purge();
SceneEditorTestLayer::onExit();
}

cocos2d::CCNode* UIComponentTest::createGameScene()
{
//创建一个Node 读取场景编辑器导出的json文件
CCNode *pNode = SceneReader::sharedSceneReader()->createNodeWithSceneFile("scenetest/UIComponentTest/UIComponentTest.json");
if (pNode == NULL)
{
return NULL;
}
_node = pNode;

//得到场景里面有个UI控件 tag 10025 类型是GUIComponent
CCComRender *render = static_cast<CCComRender*>(_node->getChildByTag(10025)->getComponent("GUIComponent"));
//得到UI里面所有的 控件
cocos2d::gui::TouchGroup* touchGroup = static_cast<cocos2d::gui::TouchGroup*>(render->getNode());
//获得画布
UIWidget* widget = static_cast<UIWidget*>(touchGroup->getWidgetByName("Panel_154"));
//获得按钮
UIButton* button = static_cast<UIButton*>(widget->getChildByName("Button_156"));
//设置按钮的点击事件监听
button->addTouchEventListener(this,toucheventselector(UIComponentTest::touchEvent));

return pNode;
}

void UIComponentTest::touchEvent(CCObject *pSender,TouchEventType type)
{
switch (type)
{
case TOUCH_EVENT_BEGAN: //当点击开始的时候触发
{
//得到场景里面的动画控件
CCComRender *pBlowFish = static_cast<CCComRender*>(_node->getChildByTag(10010)->getComponent("CCArmature"));
//动画移动
pBlowFish->getNode()->runAction(CCMoveBy::create(10.0f,ccp(-1000.0f,0)));

CCComRender *pButterflyfish = static_cast<CCComRender*>(_node->getChildByTag(10011)->getComponent("CCArmature"));
pButterflyfish->getNode()->runAction(CCMoveBy::create(10.0f,0)));
}
break;
default:
break;
}
}

就这些吧 ,以后自己就会用了 ..


from:http://www.58player.com/article-59907-1.html

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读