UI自定义控件--制作Armature的动画,不能显示,请教大神

在导入dll,制作UI资源后,生成了json文件

然后我在HelloWorld工程中解析:

以下是我的解析类:

#include “cocos2d.h”
#include “ui/CocosGUI.h”
#include “CocoStudio.h”

class ArmatureWidget : public cocos2d::ui::Widget
{
public:
ArmatureWidget();
~ArmatureWidget();

static ArmatureWidget* create();
static cocos2d::Ref* createInstance();

void setExportJson(const char* jsonFile);
const char* getExportJson() const;

void setArmatureName(std::string name);
std::string getArmatureName() const;

void play();

protected:
virtual bool init();
virtual void initRenderer();

virtual void removeAllChildren();

protected:
std::string m_strExportJson;
std::string m_strArmatureName;

cocostudio::Armature* armature;
};

#include “ArmatureWidget.h”

USING_NS_CC;
using namespace cocostudio;

ArmatureWidget::ArmatureWidget() : m_strExportJson(""),
m_strArmatureName("")
{}

ArmatureWidget::~ArmatureWidget()
{}

ArmatureWidget* ArmatureWidget::create()
{
ArmatureWidget* widget = new ArmatureWidget();

if (widget && widget->init())
{
widget->autorelease();
return widget;
}
CC_SAFE_DELETE(widget);
return NULL;
}
cocos2d::CCObject* ArmatureWidget::createInstance()
{
return create();
}

bool ArmatureWidget::init()
{
if (Widget::init())
{
return true;
}
return false;
}
void ArmatureWidget::initRenderer()
{
Widget::initRenderer();

armature = Armature::create();
}

void ArmatureWidget::removeAllChildren()
{
Widget::removeAllChildren();
}

void ArmatureWidget::setExportJson(const char* jsonFile)
{
m_strExportJson = jsonFile;
}
const char* ArmatureWidget::getExportJson() const
{
return m_strExportJson.c_str();
}

void ArmatureWidget::setArmatureName(std::string name)
{
m_strArmatureName = name;
}

std::string ArmatureWidget::getArmatureName() const
{
return m_strArmatureName;
}

void ArmatureWidget::play()
{
const char* file = m_strExportJson.c_str();
ArmatureDataManager::getInstance()->addArmatureFileInfo(file);

const char* name = m_strArmatureName.c_str();
armature->init(name);
armature->getAnimation()->playWithIndex(0);

}

、、、、、、、、、、、、、、、、

、、、、、、、、、、、、、、、、

#pragma once

#include “extensions/cocos-ext.h”
#include “cocostudio/DictionaryHelper.h”
#include “ui/CocosGUI.h”

class ArmatureWidgetReader : public cocos2d::Ref
{
public:
ArmatureWidgetReader();
~ArmatureWidgetReader();

static ArmatureWidgetReader* getInstance();
static void purge();

virtual void setProperties(const std::string& classType, cocos2d::ui::Widget* widget, const rapidjson::Value& customOptions);
};

#include “ArmatureWidgetReader.h”
#include “ArmatureWidget.h”
#include “cocostudio/CCSGUIReader.h”

USING_NS_CC;
USING_NS_CC_EXT;
using namespace ui;
using namespace cocostudio;

ArmatureWidgetReader::ArmatureWidgetReader()
{

}

ArmatureWidgetReader::~ArmatureWidgetReader()
{

}

static ArmatureWidgetReader* _instanceAnimateWidgetReader = NULL;

ArmatureWidgetReader* ArmatureWidgetReader::getInstance()
{
if (!_instanceAnimateWidgetReader)
{
_instanceAnimateWidgetReader = new ArmatureWidgetReader();
}
return _instanceAnimateWidgetReader;
}

void ArmatureWidgetReader::setProperties(const std::string& classType,
Widget widget,
const rapidjson::Value &customOptions)
{
GUIReader
guiReader = GUIReader::getInstance();

ArmatureWidget* custom = static_cast<ArmatureWidget*>(widget);

bool isExistJson = DICTOOL->checkObjectExist_json(customOptions, “ExportJson”);
bool isExistName = DICTOOL->checkObjectExist_json(customOptions, “ArmatureName”);

CC_ASSERT(isExistJson);
CC_ASSERT(isExistName);

const char* jsonfile = DICTOOL->getStringValue_json(customOptions, “ExportJson”);
custom->setExportJson(jsonfile);

const char* animName = DICTOOL->getStringValue_json(customOptions, “ArmatureName”);
custom->setArmatureName(animName);

// custom->play();
}

、、、、、、、、、、、、、、、、、、、、、、
、、、、、、、、、、、、、、、、、、、、、、

在HelloWorld::onEnter() 里添加:

    Layer::onEnter();

GUIReader* guiReader = GUIReader::getInstance();
guiReader->registerTypeAndCallBack(“ArmatureWidget”,
&ArmatureWidget::createInstance,
ArmatureWidgetReader::getInstance(),
parseselector(ArmatureWidgetReader::setProperties));

Layout* layout = static_cast<Layout*>(cocostudio::GUIReader::getInstance()->widgetFromJsonFile(
“ArmatureWidgetTest_1.json”));
addChild(layout);

auto armatureWidget = dynamic_cast<ArmatureWidget*>(Helper::seekWidgetByName(layout, “Widget_22”));
armatureWidget->play();
armatureWidget->addTouchEventListener(this, toucheventselector(HelloWorld::onButtonTouch));

运行后不能显示出动画。。。

就大神指点。。。谢谢

问题在于没有寻找资源路径。。。:8::3: