mac cocostudio尀cocostudio.h 怎么包含

2025-05-08 02:33:40
推荐回答(1个)
回答1:

需要包含的头文件及名字空间:
?

1
2
3

  1. #include "cocostudio/CocoStudio.h"
  2. #include "ui/CocosGUI.h"
  3. using namespace cocos2d::ui;
  4. using namespace cocostudio;
    注:工程中需要附加包含的头文件目录:$(EngineRoot)cocos\editor-support,因为cocostudio在此目录下。


获取UI控件的方法如下:

m_achievementLayer = dynamic_cast(GUIReader::getInstance()->widgetFromJsonFile("achievements/achievements.json"));
addChild(m_achievementLayer);

Widget* scoreWidget = dynamic_cast(m_achievementLayer->getChildByName("ImageView_231"));
m_score = dynamic_cast(scoreWidget->getChildByName("LabelAtlas_307"));
m_score->setStringValue("45");


添加按钮回调事件

Button* startButton = dynamic_cast(m_achievementLayer->getChildByName("Button_336"));
startButton->addTouchEventListener(this, toucheventselector(GameScene::touchStartButton));


利用addTouchEventListener函数就可以绑定按钮的回调事件了~

回调函数实现:

void GameScene::touchStartButton(Ref* pSender, TouchEventType type)
{
switch (type)
{
case TOUCH_EVENT_ENDED:
//do something
break;
}
}