Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
71 changes: 70 additions & 1 deletion dragonbones/renderer/DBArmature.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,18 @@ DBArmature* DBArmature::create(const std::string &dragonBonesName,const std::str
return nullptr;
}

DBArmature* DBArmature::createWithData(const std::string& dragonBonesName, const std::string& dragonbonesDataName)
{
DBArmature* armature = new (std::nothrow) DBArmature();
if (armature && armature->initWithDataName(dragonBonesName, dragonbonesDataName))
{
armature->autorelease();
return armature;
}
CC_SAFE_DELETE(armature);
return nullptr;
}


bool DBArmature::initWithName(const std::string &name)
{
Expand Down Expand Up @@ -149,6 +161,63 @@ bool DBArmature::initWithName(const std::string &name,const std::string &texture
return true;
}

bool DBArmature::initWithDataName(const std::string& name, const std::string& dataName)
{
CC_SAFE_RELEASE_NULL(_eventDataMgr);
_eventDataMgr = DBEventDataMgr::create();
CC_SAFE_RETAIN(_eventDataMgr);

DragonBonesData* dragonBonesData = DBCCFactory::getInstance()->getDragonBonesData(dataName);
if (!dragonBonesData)
{
return false;
}

float version = atof(dragonBonesData->version.c_str());
if (version >= 4.5)
{
this->_skewEnable = true;
}

_pArmatureData = dragonBonesData->getArmatureData(name);
if (!_pArmatureData)
{
_pArmatureData = dragonBonesData->getArmatureDataFirst();
if (!_pArmatureData)
{
return false;
}
}

_name = name;
DBAnimation* animation = DBAnimation::create(this);
this->setAnimation(animation);
animation->setAnimationDataList(_pArmatureData->animationDataList);

for (size_t i = 0, l = _pArmatureData->boneDataList.size(); i < l; ++i)
{
createBone(_pArmatureData->boneDataList.at(i));
}

buildIK();
updateBoneCache();
createSkin(dataName);


this->setCascadeColorEnabled(true);
this->setCascadeOpacityEnabled(true);


// update armature pose
getAnimation()->play();
update(0);
getAnimation()->stop();

dragonBonesData->retain();

return true;
}

void DBArmature::setDragonBonesData(dragonBones::DragonBonesData *data)
{
CC_SAFE_RELEASE_NULL(_pDragonBonesData);
Expand Down Expand Up @@ -410,4 +479,4 @@ DBEventDataMgr* DBArmature::getEventDataManager() const



NAME_SPACE_DRAGON_BONES_END
NAME_SPACE_DRAGON_BONES_END