mirror of https://github.com/axmolengine/axmol.git
commit
113fa9924e
|
@ -85,8 +85,6 @@ Armature::Armature()
|
||||||
, _batchNode(nullptr)
|
, _batchNode(nullptr)
|
||||||
, _parentBone(nullptr)
|
, _parentBone(nullptr)
|
||||||
, _armatureTransformDirty(true)
|
, _armatureTransformDirty(true)
|
||||||
, _boneDic(nullptr)
|
|
||||||
, _topBoneList(nullptr)
|
|
||||||
, _animation(nullptr)
|
, _animation(nullptr)
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
@ -94,16 +92,9 @@ Armature::Armature()
|
||||||
|
|
||||||
Armature::~Armature(void)
|
Armature::~Armature(void)
|
||||||
{
|
{
|
||||||
if(nullptr != _boneDic)
|
_boneDic.clear();
|
||||||
{
|
_topBoneList.clear();
|
||||||
_boneDic->removeAllObjects();
|
|
||||||
CC_SAFE_DELETE(_boneDic);
|
|
||||||
}
|
|
||||||
if (nullptr != _topBoneList)
|
|
||||||
{
|
|
||||||
_topBoneList->removeAllObjects();
|
|
||||||
CC_SAFE_DELETE(_topBoneList);
|
|
||||||
}
|
|
||||||
CC_SAFE_DELETE(_animation);
|
CC_SAFE_DELETE(_animation);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -125,16 +116,10 @@ bool Armature::init(const char *name)
|
||||||
_animation = new ArmatureAnimation();
|
_animation = new ArmatureAnimation();
|
||||||
_animation->init(this);
|
_animation->init(this);
|
||||||
|
|
||||||
CC_SAFE_DELETE(_boneDic);
|
_boneDic.clear();
|
||||||
_boneDic = new Dictionary();
|
_topBoneList.clear();
|
||||||
|
|
||||||
CC_SAFE_DELETE(_topBoneList);
|
|
||||||
_topBoneList = new Array();
|
|
||||||
_topBoneList->init();
|
|
||||||
|
|
||||||
_blendFunc.src = CC_BLEND_SRC;
|
|
||||||
_blendFunc.dst = CC_BLEND_DST;
|
|
||||||
|
|
||||||
|
_blendFunc = BlendFunc::ALPHA_NON_PREMULTIPLIED;
|
||||||
|
|
||||||
_name = name == nullptr ? "" : name;
|
_name = name == nullptr ? "" : name;
|
||||||
|
|
||||||
|
@ -155,22 +140,18 @@ bool Armature::init(const char *name)
|
||||||
|
|
||||||
_armatureData = armatureData;
|
_armatureData = armatureData;
|
||||||
|
|
||||||
|
for (auto& element : armatureData->boneDataDic)
|
||||||
DictElement *_element = nullptr;
|
|
||||||
Dictionary *boneDataDic = &armatureData->boneDataDic;
|
|
||||||
CCDICT_FOREACH(boneDataDic, _element)
|
|
||||||
{
|
{
|
||||||
Bone *bone = createBone(_element->getStrKey());
|
Bone *bone = createBone(element.first.c_str());
|
||||||
|
|
||||||
//! init bone's Tween to 1st movement's 1st frame
|
//! init bone's Tween to 1st movement's 1st frame
|
||||||
do
|
do
|
||||||
{
|
{
|
||||||
|
|
||||||
MovementData *movData = animationData->getMovement(animationData->movementNames.at(0).c_str());
|
MovementData *movData = animationData->getMovement(animationData->movementNames.at(0).c_str());
|
||||||
CC_BREAK_IF(!movData);
|
CC_BREAK_IF(!movData);
|
||||||
|
|
||||||
MovementBoneData *movBoneData = movData->getMovementBoneData(bone->getName().c_str());
|
MovementBoneData *movBoneData = movData->getMovementBoneData(bone->getName().c_str());
|
||||||
CC_BREAK_IF(!movBoneData || movBoneData->frameList.count() <= 0);
|
CC_BREAK_IF(!movBoneData || movBoneData->frameList.size() <= 0);
|
||||||
|
|
||||||
FrameData *frameData = movBoneData->getFrameData(0);
|
FrameData *frameData = movBoneData->getFrameData(0);
|
||||||
CC_BREAK_IF(!frameData);
|
CC_BREAK_IF(!frameData);
|
||||||
|
@ -255,28 +236,28 @@ Bone *Armature::createBone(const char *boneName)
|
||||||
void Armature::addBone(Bone *bone, const char *parentName)
|
void Armature::addBone(Bone *bone, const char *parentName)
|
||||||
{
|
{
|
||||||
CCASSERT( bone != nullptr, "Argument must be non-nil");
|
CCASSERT( bone != nullptr, "Argument must be non-nil");
|
||||||
CCASSERT(_boneDic->objectForKey(bone->getName()) == nullptr, "bone already added. It can't be added again");
|
CCASSERT(_boneDic.at(bone->getName()) == nullptr, "bone already added. It can't be added again");
|
||||||
|
|
||||||
if (nullptr != parentName)
|
if (nullptr != parentName)
|
||||||
{
|
{
|
||||||
Bone *boneParent = (Bone *)_boneDic->objectForKey(parentName);
|
Bone *boneParent = _boneDic.at(parentName);
|
||||||
if (boneParent)
|
if (boneParent)
|
||||||
{
|
{
|
||||||
boneParent->addChildBone(bone);
|
boneParent->addChildBone(bone);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
_topBoneList->addObject(bone);
|
_topBoneList.pushBack(bone);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
_topBoneList->addObject(bone);
|
_topBoneList.pushBack(bone);
|
||||||
}
|
}
|
||||||
|
|
||||||
bone->setArmature(this);
|
bone->setArmature(this);
|
||||||
|
|
||||||
_boneDic->setObject(bone, bone->getName());
|
_boneDic.insert(bone->getName(), bone);
|
||||||
addChild(bone);
|
addChild(bone);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -288,18 +269,18 @@ void Armature::removeBone(Bone *bone, bool recursion)
|
||||||
bone->setArmature(nullptr);
|
bone->setArmature(nullptr);
|
||||||
bone->removeFromParent(recursion);
|
bone->removeFromParent(recursion);
|
||||||
|
|
||||||
if (_topBoneList->containsObject(bone))
|
if (_topBoneList.contains(bone))
|
||||||
{
|
{
|
||||||
_topBoneList->removeObject(bone);
|
_topBoneList.eraseObject(bone);
|
||||||
}
|
}
|
||||||
_boneDic->removeObjectForKey(bone->getName());
|
_boneDic.erase(bone->getName());
|
||||||
removeChild(bone, true);
|
removeChild(bone, true);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
Bone *Armature::getBone(const char *name) const
|
Bone *Armature::getBone(const char *name) const
|
||||||
{
|
{
|
||||||
return (Bone *)_boneDic->objectForKey(name);
|
return _boneDic.at(name);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -315,24 +296,24 @@ void Armature::changeBoneParent(Bone *bone, const char *parentName)
|
||||||
|
|
||||||
if (parentName != nullptr)
|
if (parentName != nullptr)
|
||||||
{
|
{
|
||||||
Bone *boneParent = (Bone *)_boneDic->objectForKey(parentName);
|
Bone *boneParent = _boneDic.at(parentName);
|
||||||
|
|
||||||
if (boneParent)
|
if (boneParent)
|
||||||
{
|
{
|
||||||
boneParent->addChildBone(bone);
|
boneParent->addChildBone(bone);
|
||||||
if (_topBoneList->containsObject(bone))
|
if (_topBoneList.contains(bone))
|
||||||
{
|
{
|
||||||
_topBoneList->removeObject(bone);
|
_topBoneList.eraseObject(bone);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
_topBoneList->addObject(bone);
|
_topBoneList.pushBack(bone);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
Dictionary *Armature::getBoneDic() const
|
const cocos2d::Map<std::string, Bone*>& Armature::getBoneDic() const
|
||||||
{
|
{
|
||||||
return _boneDic;
|
return _boneDic;
|
||||||
}
|
}
|
||||||
|
@ -376,10 +357,9 @@ void Armature::update(float dt)
|
||||||
{
|
{
|
||||||
_animation->update(dt);
|
_animation->update(dt);
|
||||||
|
|
||||||
for (auto object : *_topBoneList)
|
std::for_each(_topBoneList.begin(), _topBoneList.end(), [&dt](Bone* bone){
|
||||||
{
|
bone->update(dt);
|
||||||
static_cast<Bone*>(object)->update(dt);
|
});
|
||||||
}
|
|
||||||
|
|
||||||
_armatureTransformDirty = false;
|
_armatureTransformDirty = false;
|
||||||
}
|
}
|
||||||
|
@ -392,7 +372,7 @@ void Armature::draw()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
for (auto object : _children)
|
for (auto& object : _children)
|
||||||
{
|
{
|
||||||
if (Bone *bone = dynamic_cast<Bone *>(object))
|
if (Bone *bone = dynamic_cast<Bone *>(object))
|
||||||
{
|
{
|
||||||
|
@ -408,12 +388,11 @@ void Armature::draw()
|
||||||
Skin *skin = static_cast<Skin *>(node);
|
Skin *skin = static_cast<Skin *>(node);
|
||||||
skin->updateTransform();
|
skin->updateTransform();
|
||||||
|
|
||||||
BlendType blendType = bone->getBlendType();
|
bool blendDirty = bone->isBlendDirty();
|
||||||
|
|
||||||
if (blendType != BLEND_NORMAL)
|
if (blendDirty)
|
||||||
{
|
{
|
||||||
updateBlendType(blendType);
|
skin->setBlendFunc(bone->getBlendFunc());
|
||||||
skin->setBlendFunc(_blendFunc);
|
|
||||||
}
|
}
|
||||||
skin->draw();
|
skin->draw();
|
||||||
}
|
}
|
||||||
|
@ -440,47 +419,6 @@ void Armature::draw()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
void Armature::updateBlendType(BlendType blendType)
|
|
||||||
{
|
|
||||||
BlendFunc blendFunc;
|
|
||||||
switch (blendType)
|
|
||||||
{
|
|
||||||
case BLEND_NORMAL:
|
|
||||||
{
|
|
||||||
blendFunc.src = CC_BLEND_SRC;
|
|
||||||
blendFunc.dst = CC_BLEND_DST;
|
|
||||||
}
|
|
||||||
break;
|
|
||||||
case BLEND_ADD:
|
|
||||||
{
|
|
||||||
blendFunc.src = GL_SRC_ALPHA;
|
|
||||||
blendFunc.dst = GL_ONE;
|
|
||||||
}
|
|
||||||
break;
|
|
||||||
case BLEND_MULTIPLY:
|
|
||||||
{
|
|
||||||
blendFunc.src = GL_DST_COLOR;
|
|
||||||
blendFunc.dst = GL_ONE_MINUS_SRC_ALPHA;
|
|
||||||
}
|
|
||||||
break;
|
|
||||||
case BLEND_SCREEN:
|
|
||||||
{
|
|
||||||
blendFunc.src = GL_ONE;
|
|
||||||
blendFunc.dst = GL_ONE_MINUS_SRC_COLOR;
|
|
||||||
}
|
|
||||||
break;
|
|
||||||
default:
|
|
||||||
{
|
|
||||||
blendFunc.src = CC_BLEND_SRC;
|
|
||||||
blendFunc.dst = CC_BLEND_DST;
|
|
||||||
}
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
GL::blendFunc(blendFunc.src, blendFunc.dst);
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
void Armature::visit()
|
void Armature::visit()
|
||||||
{
|
{
|
||||||
// quick return if not visible. children won't be drawn.
|
// quick return if not visible. children won't be drawn.
|
||||||
|
@ -518,7 +456,7 @@ Rect Armature::getBoundingBox() const
|
||||||
|
|
||||||
Rect boundingBox = Rect(0, 0, 0, 0);
|
Rect boundingBox = Rect(0, 0, 0, 0);
|
||||||
|
|
||||||
for(auto object : _children)
|
for_each(_children.begin(), _children.end(), [&minx, &miny, &maxx, &maxy, &first, &boundingBox](Node *object)
|
||||||
{
|
{
|
||||||
if (Bone *bone = dynamic_cast<Bone *>(object))
|
if (Bone *bone = dynamic_cast<Bone *>(object))
|
||||||
{
|
{
|
||||||
|
@ -543,7 +481,8 @@ Rect Armature::getBoundingBox() const
|
||||||
|
|
||||||
boundingBox.setRect(minx, miny, maxx - minx, maxy - miny);
|
boundingBox.setRect(minx, miny, maxx - minx, maxy - miny);
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
});
|
||||||
|
|
||||||
return RectApplyTransform(boundingBox, getNodeToParentTransform());
|
return RectApplyTransform(boundingBox, getNodeToParentTransform());
|
||||||
}
|
}
|
||||||
|
@ -569,11 +508,9 @@ void Armature::setParentBone(Bone *parentBone)
|
||||||
{
|
{
|
||||||
_parentBone = parentBone;
|
_parentBone = parentBone;
|
||||||
|
|
||||||
DictElement *element = nullptr;
|
for (auto& element : _boneDic)
|
||||||
CCDICT_FOREACH(_boneDic, element)
|
|
||||||
{
|
{
|
||||||
Bone *bone = static_cast<Bone*>(element->getObject());
|
element.second->setArmature(this);
|
||||||
bone->setArmature(this);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -582,15 +519,50 @@ Bone *Armature::getParentBone() const
|
||||||
return _parentBone;
|
return _parentBone;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#if ENABLE_PHYSICS_BOX2D_DETECT || ENABLE_PHYSICS_CHIPMUNK_DETECT
|
||||||
|
|
||||||
void CCArmature::setColliderFilter(ColliderFilter *filter)
|
void CCArmature::setColliderFilter(ColliderFilter *filter)
|
||||||
{
|
{
|
||||||
DictElement *element = nullptr;
|
for (auto& element : _boneDic)
|
||||||
CCDICT_FOREACH(_boneDic, element)
|
|
||||||
{
|
{
|
||||||
Bone *bone = static_cast<Bone*>(element->getObject());
|
element.second->setColliderFilter(filter);
|
||||||
bone->setColliderFilter(filter);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
#elif ENABLE_PHYSICS_SAVE_CALCULATED_VERTEX
|
||||||
|
|
||||||
|
void CCArmature::drawContour()
|
||||||
|
{
|
||||||
|
for(auto& element : _boneDic)
|
||||||
|
{
|
||||||
|
Bone *bone = element.second;
|
||||||
|
ColliderDetector *detector = bone->getColliderDetector();
|
||||||
|
|
||||||
|
if (!detector)
|
||||||
|
continue;
|
||||||
|
|
||||||
|
const cocos2d::Vector<ColliderBody*>& bodyList = detector->getColliderBodyList();
|
||||||
|
|
||||||
|
for (auto& object : bodyList)
|
||||||
|
{
|
||||||
|
ColliderBody *body = static_cast<ColliderBody*>(object);
|
||||||
|
const std::vector<Point> &vertexList = body->getCalculatedVertexList();
|
||||||
|
|
||||||
|
unsigned long length = vertexList.size();
|
||||||
|
Point *points = new Point[length];
|
||||||
|
for (unsigned long i = 0; i<length; i++)
|
||||||
|
{
|
||||||
|
Point p = vertexList.at(i);
|
||||||
|
points[i].x = p.x;
|
||||||
|
points[i].y = p.y;
|
||||||
|
}
|
||||||
|
DrawPrimitives::drawPoly( points, (unsigned int)length, true );
|
||||||
|
|
||||||
|
delete points;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
#endif
|
||||||
|
|
||||||
#if ENABLE_PHYSICS_BOX2D_DETECT
|
#if ENABLE_PHYSICS_BOX2D_DETECT
|
||||||
b2Body *Armature::getBody() const
|
b2Body *Armature::getBody() const
|
||||||
|
@ -608,11 +580,11 @@ void Armature::setBody(b2Body *body)
|
||||||
_body = body;
|
_body = body;
|
||||||
_body->SetUserData(this);
|
_body->SetUserData(this);
|
||||||
|
|
||||||
for(auto object : *_children)
|
for(auto& object : _children)
|
||||||
{
|
{
|
||||||
if (Bone *bone = dynamic_cast<Bone *>(object))
|
if (Bone *bone = dynamic_cast<Bone *>(object))
|
||||||
{
|
{
|
||||||
Array *displayList = bone->getDisplayManager()->getDecorativeDisplayList();
|
auto displayList = bone->getDisplayManager()->getDecorativeDisplayList();
|
||||||
|
|
||||||
for(auto displayObject : displayList)
|
for(auto displayObject : displayList)
|
||||||
{
|
{
|
||||||
|
@ -654,20 +626,20 @@ void Armature::setBody(cpBody *body)
|
||||||
_body = body;
|
_body = body;
|
||||||
_body->data = this;
|
_body->data = this;
|
||||||
|
|
||||||
for(auto object: _children)
|
for (auto& object : _children)
|
||||||
{
|
{
|
||||||
if (Bone *bone = dynamic_cast<Bone *>(object))
|
if (Bone *bone = dynamic_cast<Bone *>(object))
|
||||||
{
|
{
|
||||||
Array *displayList = bone->getDisplayManager()->getDecorativeDisplayList();
|
auto displayList = bone->getDisplayManager()->getDecorativeDisplayList();
|
||||||
|
|
||||||
for(auto displayObject: *displayList)
|
for_each(displayList.begin(), displayList.end(), [&body](DecorativeDisplay* displayObject)
|
||||||
{
|
{
|
||||||
ColliderDetector *detector = static_cast<DecorativeDisplay *>(displayObject)->getColliderDetector();
|
ColliderDetector *detector = displayObject->getColliderDetector();
|
||||||
if (detector != nullptr)
|
if (detector != nullptr)
|
||||||
{
|
{
|
||||||
detector->setBody(_body);
|
detector->setBody(body);
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -143,7 +143,7 @@ public:
|
||||||
* Get Armature's bone dictionary
|
* Get Armature's bone dictionary
|
||||||
* @return Armature's bone dictionary
|
* @return Armature's bone dictionary
|
||||||
*/
|
*/
|
||||||
cocos2d::Dictionary *getBoneDic() const;
|
const cocos2d::Map<std::string, Bone*>& getBoneDic() const;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* This boundingBox will calculate all bones' boundingBox every time
|
* This boundingBox will calculate all bones' boundingBox every time
|
||||||
|
@ -184,7 +184,12 @@ public:
|
||||||
|
|
||||||
virtual bool getArmatureTransformDirty() const;
|
virtual bool getArmatureTransformDirty() const;
|
||||||
|
|
||||||
|
|
||||||
|
#if ENABLE_PHYSICS_BOX2D_DETECT || ENABLE_PHYSICS_CHIPMUNK_DETECT
|
||||||
virtual void setColliderFilter(ColliderFilter *filter);
|
virtual void setColliderFilter(ColliderFilter *filter);
|
||||||
|
#elif ENABLE_PHYSICS_SAVE_CALCULATED_VERTEX
|
||||||
|
virtual void drawContour();
|
||||||
|
#endif
|
||||||
|
|
||||||
|
|
||||||
virtual void setArmatureData(ArmatureData *armatureData) { _armatureData = armatureData; }
|
virtual void setArmatureData(ArmatureData *armatureData) { _armatureData = armatureData; }
|
||||||
|
@ -242,12 +247,6 @@ protected:
|
||||||
*/
|
*/
|
||||||
Bone *createBone(const char *boneName );
|
Bone *createBone(const char *boneName );
|
||||||
|
|
||||||
/**! Update blend function
|
|
||||||
* @js NA
|
|
||||||
* @lua NA
|
|
||||||
*/
|
|
||||||
void updateBlendType(BlendType blendType);
|
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
ArmatureData *_armatureData;
|
ArmatureData *_armatureData;
|
||||||
|
|
||||||
|
@ -259,9 +258,9 @@ protected:
|
||||||
|
|
||||||
mutable bool _armatureTransformDirty;
|
mutable bool _armatureTransformDirty;
|
||||||
|
|
||||||
cocos2d::Dictionary *_boneDic; //! The dictionary of the bones, include all bones in the armature, no matter it is the direct bone or the indirect bone. It is different from m_pChindren.
|
cocos2d::Map<std::string, Bone*> _boneDic; //! The dictionary of the bones, include all bones in the armature, no matter it is the direct bone or the indirect bone. It is different from m_pChindren.
|
||||||
|
|
||||||
cocos2d::Array *_topBoneList;
|
cocos2d::Vector<Bone*> _topBoneList;
|
||||||
|
|
||||||
cocos2d::BlendFunc _blendFunc; //! It's required for CCTextureProtocol inheritance
|
cocos2d::BlendFunc _blendFunc; //! It's required for CCTextureProtocol inheritance
|
||||||
|
|
||||||
|
|
|
@ -54,21 +54,25 @@ ArmatureAnimation::ArmatureAnimation()
|
||||||
, _armature(nullptr)
|
, _armature(nullptr)
|
||||||
, _movementID("")
|
, _movementID("")
|
||||||
, _toIndex(0)
|
, _toIndex(0)
|
||||||
, _tweenList(nullptr)
|
|
||||||
, _ignoreFrameEvent(false)
|
, _ignoreFrameEvent(false)
|
||||||
|
, _onMovementList(false)
|
||||||
|
, _movementListLoop(false)
|
||||||
|
, _movementListDurationTo(-1)
|
||||||
, _userObject(nullptr)
|
, _userObject(nullptr)
|
||||||
|
|
||||||
, _movementEventCallFunc(nullptr)
|
, _movementEventCallFunc(nullptr)
|
||||||
, _frameEventCallFunc(nullptr)
|
, _frameEventCallFunc(nullptr)
|
||||||
, _movementEventTarget(nullptr)
|
, _movementEventTarget(nullptr)
|
||||||
, _frameEventTarget(nullptr)
|
, _frameEventTarget(nullptr)
|
||||||
|
|
||||||
|
, _movementEventListener(nullptr)
|
||||||
|
, _frameEventListener(nullptr)
|
||||||
{
|
{
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
ArmatureAnimation::~ArmatureAnimation(void)
|
ArmatureAnimation::~ArmatureAnimation(void)
|
||||||
{
|
{
|
||||||
CC_SAFE_RELEASE_NULL(_tweenList);
|
|
||||||
CC_SAFE_RELEASE_NULL(_animationData);
|
CC_SAFE_RELEASE_NULL(_animationData);
|
||||||
|
|
||||||
CC_SAFE_RELEASE_NULL(_userObject);
|
CC_SAFE_RELEASE_NULL(_userObject);
|
||||||
|
@ -81,8 +85,7 @@ bool ArmatureAnimation::init(Armature *armature)
|
||||||
{
|
{
|
||||||
_armature = armature;
|
_armature = armature;
|
||||||
|
|
||||||
_tweenList = new Array();
|
_tweenList.clear();
|
||||||
_tweenList->init();
|
|
||||||
|
|
||||||
bRet = true;
|
bRet = true;
|
||||||
}
|
}
|
||||||
|
@ -92,31 +95,31 @@ bool ArmatureAnimation::init(Armature *armature)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
void ArmatureAnimation:: pause()
|
void ArmatureAnimation::pause()
|
||||||
{
|
{
|
||||||
for(auto object : *_tweenList)
|
for_each(_tweenList.begin(), _tweenList.end(), [](Tween *tween)
|
||||||
{
|
{
|
||||||
static_cast<Tween*>(object)->pause();
|
tween->pause();
|
||||||
}
|
});
|
||||||
ProcessBase::pause();
|
ProcessBase::pause();
|
||||||
}
|
}
|
||||||
|
|
||||||
void ArmatureAnimation::resume()
|
void ArmatureAnimation::resume()
|
||||||
{
|
{
|
||||||
for(auto object : *_tweenList)
|
for_each(_tweenList.begin(), _tweenList.end(), [](Tween *tween)
|
||||||
{
|
{
|
||||||
static_cast<Tween*>(object)->resume();
|
tween->resume();
|
||||||
}
|
});
|
||||||
ProcessBase::resume();
|
ProcessBase::resume();
|
||||||
}
|
}
|
||||||
|
|
||||||
void ArmatureAnimation::stop()
|
void ArmatureAnimation::stop()
|
||||||
{
|
{
|
||||||
for(auto object : *_tweenList)
|
for_each(_tweenList.begin(), _tweenList.end(), [](Tween *tween)
|
||||||
{
|
{
|
||||||
static_cast<Tween*>(object)->stop();
|
tween->stop();
|
||||||
}
|
});
|
||||||
_tweenList->removeAllObjects();
|
_tweenList.clear();
|
||||||
ProcessBase::stop();
|
ProcessBase::stop();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -142,11 +145,10 @@ void ArmatureAnimation::setSpeedScale(float speedScale)
|
||||||
|
|
||||||
_processScale = !_movementData ? _speedScale : _speedScale * _movementData->scale;
|
_processScale = !_movementData ? _speedScale : _speedScale * _movementData->scale;
|
||||||
|
|
||||||
DictElement *element = nullptr;
|
const Map<std::string, Bone*>& map = _armature->getBoneDic();
|
||||||
const Dictionary *dict = _armature->getBoneDic();
|
for(auto& element : map)
|
||||||
CCDICT_FOREACH(dict, element)
|
|
||||||
{
|
{
|
||||||
Bone *bone = static_cast<Bone*>(element->getObject());
|
Bone *bone = element.second;
|
||||||
|
|
||||||
bone->getTween()->setProcessScale(_processScale);
|
bone->getTween()->setProcessScale(_processScale);
|
||||||
if (bone->getChildArmature())
|
if (bone->getChildArmature())
|
||||||
|
@ -161,30 +163,8 @@ float ArmatureAnimation::getSpeedScale() const
|
||||||
return _speedScale;
|
return _speedScale;
|
||||||
}
|
}
|
||||||
|
|
||||||
void ArmatureAnimation::setAnimationInternal(float animationInternal)
|
|
||||||
{
|
|
||||||
if(animationInternal == _animationInternal)
|
|
||||||
{
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
_animationInternal = animationInternal;
|
void ArmatureAnimation::play(const char *animationName, int durationTo, int loop)
|
||||||
|
|
||||||
DictElement *element = nullptr;
|
|
||||||
const Dictionary *dict = _armature->getBoneDic();
|
|
||||||
CCDICT_FOREACH(dict, element)
|
|
||||||
{
|
|
||||||
Bone *bone = static_cast<Bone*>(element->getObject());
|
|
||||||
bone->getTween()->setAnimationInternal(_animationInternal);
|
|
||||||
if (bone->getChildArmature())
|
|
||||||
{
|
|
||||||
bone->getChildArmature()->getAnimation()->setAnimationInternal(_animationInternal);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
void ArmatureAnimation::play(const char *animationName, int durationTo, int durationTween, int loop, int tweenEasing)
|
|
||||||
{
|
{
|
||||||
CCASSERT(_animationData, "_animationData can not be null");
|
CCASSERT(_animationData, "_animationData can not be null");
|
||||||
|
|
||||||
|
@ -201,12 +181,12 @@ void ArmatureAnimation::play(const char *animationName, int durationTo, int dura
|
||||||
//! Further processing parameters
|
//! Further processing parameters
|
||||||
durationTo = (durationTo == -1) ? _movementData->durationTo : durationTo;
|
durationTo = (durationTo == -1) ? _movementData->durationTo : durationTo;
|
||||||
|
|
||||||
durationTween = (durationTween == -1) ? _movementData->durationTween : durationTween;
|
int durationTween = _movementData->durationTween == 0 ? _rawDuration : _movementData->durationTween;
|
||||||
durationTween = (durationTween == 0) ? _movementData->duration : durationTween;
|
|
||||||
|
|
||||||
tweenEasing = (tweenEasing == TWEEN_EASING_MAX) ? _movementData->tweenEasing : tweenEasing;
|
TweenType tweenEasing = _movementData->tweenEasing;
|
||||||
loop = (loop < 0) ? _movementData->loop : loop;
|
loop = (loop < 0) ? _movementData->loop : loop;
|
||||||
|
|
||||||
|
_onMovementList = false;
|
||||||
|
|
||||||
ProcessBase::play(durationTo, durationTween, loop, tweenEasing);
|
ProcessBase::play(durationTo, durationTween, loop, tweenEasing);
|
||||||
|
|
||||||
|
@ -224,36 +204,31 @@ void ArmatureAnimation::play(const char *animationName, int durationTo, int dura
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
_loopType = ANIMATION_NO_LOOP;
|
_loopType = ANIMATION_NO_LOOP;
|
||||||
_rawDuration --;
|
|
||||||
}
|
}
|
||||||
_durationTween = durationTween;
|
_durationTween = durationTween;
|
||||||
}
|
}
|
||||||
|
|
||||||
MovementBoneData *movementBoneData = nullptr;
|
MovementBoneData *movementBoneData = nullptr;
|
||||||
_tweenList->removeAllObjects();
|
_tweenList.clear();
|
||||||
|
|
||||||
DictElement *element = nullptr;
|
const Map<std::string, Bone*>& map = _armature->getBoneDic();
|
||||||
const Dictionary *dict = _armature->getBoneDic();
|
for(auto& element : map)
|
||||||
|
|
||||||
CCDICT_FOREACH(dict, element)
|
|
||||||
{
|
{
|
||||||
Bone *bone = static_cast<Bone*>(element->getObject());
|
Bone *bone = element.second;
|
||||||
movementBoneData = static_cast<MovementBoneData *>(_movementData->movBoneDataDic.objectForKey(bone->getName()));
|
movementBoneData = static_cast<MovementBoneData *>(_movementData->movBoneDataDic.at(bone->getName()));
|
||||||
|
|
||||||
Tween *tween = bone->getTween();
|
Tween *tween = bone->getTween();
|
||||||
if(movementBoneData && movementBoneData->frameList.count() > 0)
|
if(movementBoneData && movementBoneData->frameList.size() > 0)
|
||||||
{
|
{
|
||||||
_tweenList->addObject(tween);
|
_tweenList.pushBack(tween);
|
||||||
movementBoneData->duration = _movementData->duration;
|
movementBoneData->duration = _movementData->duration;
|
||||||
tween->play(movementBoneData, durationTo, durationTween, loop, tweenEasing);
|
tween->play(movementBoneData, durationTo, durationTween, loop, tweenEasing);
|
||||||
|
|
||||||
tween->setProcessScale(_processScale);
|
tween->setProcessScale(_processScale);
|
||||||
tween->setAnimationInternal(_animationInternal);
|
|
||||||
|
|
||||||
if (bone->getChildArmature())
|
if (bone->getChildArmature())
|
||||||
{
|
{
|
||||||
bone->getChildArmature()->getAnimation()->setProcessScale(_processScale);
|
bone->getChildArmature()->getAnimation()->setProcessScale(_processScale);
|
||||||
bone->getChildArmature()->getAnimation()->setAnimationInternal(_animationInternal);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
|
@ -272,13 +247,46 @@ void ArmatureAnimation::play(const char *animationName, int durationTo, int dura
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
void ArmatureAnimation::playByIndex(int animationIndex, int durationTo, int durationTween, int loop, int tweenEasing)
|
void ArmatureAnimation::playByIndex(int animationIndex, int durationTo, int loop)
|
||||||
{
|
{
|
||||||
std::vector<std::string> &movName = _animationData->movementNames;
|
std::vector<std::string> &movName = _animationData->movementNames;
|
||||||
CC_ASSERT((animationIndex > -1) && ((unsigned int)animationIndex < movName.size()));
|
CC_ASSERT((animationIndex > -1) && ((unsigned int)animationIndex < movName.size()));
|
||||||
|
|
||||||
std::string animationName = movName.at(animationIndex);
|
std::string animationName = movName.at(animationIndex);
|
||||||
play(animationName.c_str(), durationTo, durationTween, loop, tweenEasing);
|
play(animationName.c_str(), durationTo, loop);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
void ArmatureAnimation::play(const std::vector<std::string>& movementNames, int durationTo, bool loop)
|
||||||
|
{
|
||||||
|
_movementList.clear();
|
||||||
|
_movementListLoop = loop;
|
||||||
|
_movementListDurationTo = durationTo;
|
||||||
|
_onMovementList = true;
|
||||||
|
_movementIndex = 0;
|
||||||
|
|
||||||
|
_movementList = movementNames;
|
||||||
|
|
||||||
|
updateMovementList();
|
||||||
|
}
|
||||||
|
|
||||||
|
void ArmatureAnimation::playByIndex(const std::vector<int>& movementIndexes, int durationTo, bool loop)
|
||||||
|
{
|
||||||
|
_movementList.clear();
|
||||||
|
_movementListLoop = loop;
|
||||||
|
_movementListDurationTo = durationTo;
|
||||||
|
_onMovementList = true;
|
||||||
|
_movementIndex = 0;
|
||||||
|
|
||||||
|
std::vector<std::string> &movName = _animationData->movementNames;
|
||||||
|
|
||||||
|
for(auto& index : movementIndexes)
|
||||||
|
{
|
||||||
|
std::string name = movName.at(index);
|
||||||
|
_movementList.push_back(name);
|
||||||
|
}
|
||||||
|
|
||||||
|
updateMovementList();
|
||||||
}
|
}
|
||||||
|
|
||||||
void ArmatureAnimation::gotoAndPlay(int frameIndex)
|
void ArmatureAnimation::gotoAndPlay(int frameIndex)
|
||||||
|
@ -296,13 +304,14 @@ void ArmatureAnimation::gotoAndPlay(int frameIndex)
|
||||||
_isComplete = _isPause = false;
|
_isComplete = _isPause = false;
|
||||||
|
|
||||||
ProcessBase::gotoFrame(frameIndex);
|
ProcessBase::gotoFrame(frameIndex);
|
||||||
_currentPercent = (float)_curFrameIndex / (float)_movementData->duration;
|
_currentPercent = (float)_curFrameIndex / ((float)_movementData->duration-1);
|
||||||
_currentFrame = _nextFrameIndex * _currentPercent;
|
_currentFrame = _nextFrameIndex * _currentPercent;
|
||||||
|
|
||||||
for(auto object : *_tweenList)
|
|
||||||
|
for_each(_tweenList.begin(), _tweenList.end(), [&frameIndex](Tween* tween)
|
||||||
{
|
{
|
||||||
static_cast<Tween *>(object)->gotoAndPlay(frameIndex);
|
tween->gotoAndPlay(frameIndex);
|
||||||
}
|
});
|
||||||
|
|
||||||
_armature->update(0);
|
_armature->update(0);
|
||||||
|
|
||||||
|
@ -315,7 +324,7 @@ void ArmatureAnimation::gotoAndPause(int frameIndex)
|
||||||
pause();
|
pause();
|
||||||
}
|
}
|
||||||
|
|
||||||
int ArmatureAnimation::getMovementCount() const
|
long ArmatureAnimation::getMovementCount() const
|
||||||
{
|
{
|
||||||
return _animationData->getMovementCount();
|
return _animationData->getMovementCount();
|
||||||
}
|
}
|
||||||
|
@ -324,21 +333,50 @@ void ArmatureAnimation::update(float dt)
|
||||||
{
|
{
|
||||||
ProcessBase::update(dt);
|
ProcessBase::update(dt);
|
||||||
|
|
||||||
for(auto object : *_tweenList)
|
for_each(_tweenList.begin(), _tweenList.end(), [&dt](Tween* tween)
|
||||||
{
|
{
|
||||||
static_cast<Tween *>(object)->update(dt);
|
tween->update(dt);
|
||||||
}
|
});
|
||||||
|
|
||||||
while (_frameEventQueue.size() > 0)
|
while (_frameEventQueue.size() > 0)
|
||||||
{
|
{
|
||||||
FrameEvent *frameEvent = _frameEventQueue.front();
|
FrameEvent *event = _frameEventQueue.front();
|
||||||
_frameEventQueue.pop();
|
_frameEventQueue.pop();
|
||||||
|
|
||||||
_ignoreFrameEvent = true;
|
_ignoreFrameEvent = true;
|
||||||
(_frameEventTarget->*_frameEventCallFunc)(frameEvent->bone, frameEvent->frameEventName, frameEvent->originFrameIndex, frameEvent->currentFrameIndex);
|
|
||||||
|
if(_frameEventTarget)
|
||||||
|
{
|
||||||
|
(_frameEventTarget->*_frameEventCallFunc)(event->bone, event->frameEventName, event->originFrameIndex, event->currentFrameIndex);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (_frameEventListener)
|
||||||
|
{
|
||||||
|
_frameEventListener(event->bone, event->frameEventName, event->originFrameIndex, event->currentFrameIndex);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
_ignoreFrameEvent = false;
|
_ignoreFrameEvent = false;
|
||||||
|
|
||||||
CC_SAFE_DELETE(frameEvent);
|
CC_SAFE_DELETE(event);
|
||||||
|
}
|
||||||
|
|
||||||
|
while (_movementEventQueue.size() > 0)
|
||||||
|
{
|
||||||
|
MovementEvent *event = _movementEventQueue.front();
|
||||||
|
_movementEventQueue.pop();
|
||||||
|
|
||||||
|
if(_movementEventTarget)
|
||||||
|
{
|
||||||
|
(_movementEventTarget->*_movementEventCallFunc)(event->armature, event->movementType, event->movementID);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (_movementEventListener)
|
||||||
|
{
|
||||||
|
_movementEventListener(event->armature, event->movementType, event->movementID);
|
||||||
|
}
|
||||||
|
|
||||||
|
CC_SAFE_DELETE(event);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -361,10 +399,7 @@ void ArmatureAnimation::updateHandler()
|
||||||
{
|
{
|
||||||
_nextFrameIndex = _durationTween;
|
_nextFrameIndex = _durationTween;
|
||||||
|
|
||||||
if (_movementEventTarget && _movementEventCallFunc)
|
movementEvent(_armature, START, _movementID.c_str());
|
||||||
{
|
|
||||||
(_movementEventTarget->*_movementEventCallFunc)(_armature, START, _movementID.c_str());
|
|
||||||
}
|
|
||||||
|
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
@ -377,10 +412,9 @@ void ArmatureAnimation::updateHandler()
|
||||||
_isComplete = true;
|
_isComplete = true;
|
||||||
_isPlaying = false;
|
_isPlaying = false;
|
||||||
|
|
||||||
if (_movementEventTarget && _movementEventCallFunc)
|
movementEvent(_armature, COMPLETE, _movementID.c_str());
|
||||||
{
|
|
||||||
(_movementEventTarget->*_movementEventCallFunc)(_armature, COMPLETE, _movementID.c_str());
|
updateMovementList();
|
||||||
}
|
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
case ANIMATION_TO_LOOP_FRONT:
|
case ANIMATION_TO_LOOP_FRONT:
|
||||||
|
@ -390,10 +424,7 @@ void ArmatureAnimation::updateHandler()
|
||||||
_currentFrame = _nextFrameIndex == 0 ? 0 : fmodf(_currentFrame, _nextFrameIndex);
|
_currentFrame = _nextFrameIndex == 0 ? 0 : fmodf(_currentFrame, _nextFrameIndex);
|
||||||
_nextFrameIndex = _durationTween > 0 ? _durationTween : 1;
|
_nextFrameIndex = _durationTween > 0 ? _durationTween : 1;
|
||||||
|
|
||||||
if (_movementEventTarget && _movementEventCallFunc)
|
movementEvent(_armature, START, _movementID.c_str());
|
||||||
{
|
|
||||||
(_movementEventTarget->*_movementEventCallFunc)(_armature, START, _movementID.c_str());
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
|
@ -402,10 +433,7 @@ void ArmatureAnimation::updateHandler()
|
||||||
_currentFrame = fmodf(_currentFrame, _nextFrameIndex);
|
_currentFrame = fmodf(_currentFrame, _nextFrameIndex);
|
||||||
_toIndex = 0;
|
_toIndex = 0;
|
||||||
|
|
||||||
if (_movementEventTarget && _movementEventCallFunc)
|
movementEvent(_armature, LOOP_COMPLETE, _movementID.c_str());
|
||||||
{
|
|
||||||
(_movementEventTarget->*_movementEventCallFunc)(_armature, LOOP_COMPLETE, _movementID.c_str());
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
@ -433,6 +461,15 @@ void ArmatureAnimation::setFrameEventCallFunc(Object *target, SEL_FrameEventCall
|
||||||
_frameEventCallFunc = callFunc;
|
_frameEventCallFunc = callFunc;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void ArmatureAnimation::setMovementEventCallFunc(std::function<void(Armature *armature, MovementEventType movementType, const char *movementID)> listener)
|
||||||
|
{
|
||||||
|
_movementEventListener = listener;
|
||||||
|
}
|
||||||
|
void ArmatureAnimation::setFrameEventCallFunc(std::function<void(Bone *bone, const char *frameEventName, int originFrameIndex, int currentFrameIndex)> listener)
|
||||||
|
{
|
||||||
|
_frameEventListener = listener;
|
||||||
|
}
|
||||||
|
|
||||||
void ArmatureAnimation::setUserObject(Object *pUserObject)
|
void ArmatureAnimation::setUserObject(Object *pUserObject)
|
||||||
{
|
{
|
||||||
CC_SAFE_RETAIN(pUserObject);
|
CC_SAFE_RETAIN(pUserObject);
|
||||||
|
@ -442,7 +479,7 @@ void ArmatureAnimation::setUserObject(Object *pUserObject)
|
||||||
|
|
||||||
void ArmatureAnimation::frameEvent(Bone *bone, const char *frameEventName, int originFrameIndex, int currentFrameIndex)
|
void ArmatureAnimation::frameEvent(Bone *bone, const char *frameEventName, int originFrameIndex, int currentFrameIndex)
|
||||||
{
|
{
|
||||||
if (_frameEventTarget && _frameEventCallFunc)
|
if ((_frameEventTarget && _frameEventCallFunc) || _frameEventListener)
|
||||||
{
|
{
|
||||||
FrameEvent *frameEvent = new FrameEvent();
|
FrameEvent *frameEvent = new FrameEvent();
|
||||||
frameEvent->bone = bone;
|
frameEvent->bone = bone;
|
||||||
|
@ -453,4 +490,50 @@ void ArmatureAnimation::frameEvent(Bone *bone, const char *frameEventName, int o
|
||||||
_frameEventQueue.push(frameEvent);
|
_frameEventQueue.push(frameEvent);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
void ArmatureAnimation::movementEvent(Armature *armature, MovementEventType movementType, const char *movementID)
|
||||||
|
{
|
||||||
|
if ((_movementEventTarget && _movementEventCallFunc) || _movementEventListener)
|
||||||
|
{
|
||||||
|
MovementEvent *movementEvent = new MovementEvent();
|
||||||
|
movementEvent->armature = armature;
|
||||||
|
movementEvent->movementType = movementType;
|
||||||
|
movementEvent->movementID = movementID;
|
||||||
|
_movementEventQueue.push(movementEvent);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
void ArmatureAnimation::updateMovementList()
|
||||||
|
{
|
||||||
|
if (_onMovementList)
|
||||||
|
{
|
||||||
|
if (_movementListLoop)
|
||||||
|
{
|
||||||
|
play(_movementList.at(_movementIndex).c_str(), _movementListDurationTo, 0);
|
||||||
|
_movementIndex++;
|
||||||
|
|
||||||
|
if (_movementIndex >= _movementList.size())
|
||||||
|
{
|
||||||
|
_movementIndex = 0;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
if (_movementIndex < _movementList.size())
|
||||||
|
{
|
||||||
|
play(_movementList.at(_movementIndex).c_str(), _movementListDurationTo, 0);
|
||||||
|
_movementIndex++;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
_onMovementList = false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
_onMovementList = true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -27,6 +27,7 @@ THE SOFTWARE.
|
||||||
#define __CCANIMATION_H__
|
#define __CCANIMATION_H__
|
||||||
|
|
||||||
#include "cocostudio/CCProcessBase.h"
|
#include "cocostudio/CCProcessBase.h"
|
||||||
|
#include "cocostudio/CCTween.h"
|
||||||
#include <queue>
|
#include <queue>
|
||||||
|
|
||||||
namespace cocostudio {
|
namespace cocostudio {
|
||||||
|
@ -57,6 +58,13 @@ struct FrameEvent
|
||||||
int currentFrameIndex;
|
int currentFrameIndex;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
struct MovementEvent
|
||||||
|
{
|
||||||
|
Armature *armature;
|
||||||
|
MovementEventType movementType;
|
||||||
|
const char *movementID;
|
||||||
|
};
|
||||||
|
|
||||||
class ArmatureAnimation : public ProcessBase
|
class ArmatureAnimation : public ProcessBase
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
|
@ -98,7 +106,7 @@ public:
|
||||||
virtual float getSpeedScale() const;
|
virtual float getSpeedScale() const;
|
||||||
|
|
||||||
//! The animation update speed
|
//! The animation update speed
|
||||||
virtual void setAnimationInternal(float animationInternal);
|
CC_DEPRECATED_ATTRIBUTE virtual void setAnimationInternal(float animationInternal) {}
|
||||||
|
|
||||||
using ProcessBase::play;
|
using ProcessBase::play;
|
||||||
/**
|
/**
|
||||||
|
@ -109,33 +117,23 @@ public:
|
||||||
* It's meaning is changing to this animation need how many frames
|
* It's meaning is changing to this animation need how many frames
|
||||||
*
|
*
|
||||||
* -1 : use the value from MovementData get from flash design panel
|
* -1 : use the value from MovementData get from flash design panel
|
||||||
* @param durationTween The frame count you want to play in the game.
|
|
||||||
* if _durationTween is 80, then the animation will played 80 frames in a loop
|
|
||||||
*
|
|
||||||
* -1 : use the value from MovementData get from flash design panel
|
|
||||||
*
|
|
||||||
* @param loop Whether the animation is loop
|
* @param loop Whether the animation is loop
|
||||||
*
|
*
|
||||||
* loop < 0 : use the value from MovementData get from flash design panel
|
* loop < 0 : use the value from MovementData get from flash design panel
|
||||||
* loop = 0 : this animation is not loop
|
* loop = 0 : this animation is not loop
|
||||||
* loop > 0 : this animation is loop
|
* loop > 0 : this animation is loop
|
||||||
*
|
|
||||||
* @param tweenEasing Tween easing is used for calculate easing effect
|
|
||||||
*
|
|
||||||
* TWEEN_EASING_MAX : use the value from MovementData get from flash design panel
|
|
||||||
* -1 : fade out
|
|
||||||
* 0 : line
|
|
||||||
* 1 : fade in
|
|
||||||
* 2 : fade in and out
|
|
||||||
*
|
|
||||||
*/
|
*/
|
||||||
void play(const char *animationName, int durationTo = -1, int durationTween = -1, int loop = -1, int tweenEasing = TWEEN_EASING_MAX);
|
virtual void play(const char *animationName, int durationTo = -1, int loop = -1);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Play animation by index, the other param is the same to play.
|
* Play animation by index, the other param is the same to play.
|
||||||
* @param animationIndex the animation index you want to play
|
* @param animationIndex the animation index you want to play
|
||||||
*/
|
*/
|
||||||
void playByIndex(int animationIndex, int durationTo = -1, int durationTween = -1, int loop = -1, int tweenEasing = TWEEN_EASING_MAX);
|
virtual void playByIndex(int animationIndex, int durationTo = -1, int loop = -1);
|
||||||
|
|
||||||
|
|
||||||
|
virtual void play(const std::vector<std::string>& movementNames, int durationTo = -1, bool loop = true);
|
||||||
|
virtual void playByIndex(const std::vector<int>& movementIndexes, int durationTo = -1, bool loop = true);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Go to specified frame and play current movement.
|
* Go to specified frame and play current movement.
|
||||||
|
@ -171,7 +169,7 @@ public:
|
||||||
/**
|
/**
|
||||||
* Get movement count
|
* Get movement count
|
||||||
*/
|
*/
|
||||||
int getMovementCount() const;
|
long getMovementCount() const;
|
||||||
|
|
||||||
void update(float dt);
|
void update(float dt);
|
||||||
|
|
||||||
|
@ -185,13 +183,16 @@ public:
|
||||||
* Set armature's movement event callback function
|
* Set armature's movement event callback function
|
||||||
* To disconnect this event, just setMovementEventCallFunc(nullptr, nullptr);
|
* To disconnect this event, just setMovementEventCallFunc(nullptr, nullptr);
|
||||||
*/
|
*/
|
||||||
void setMovementEventCallFunc(cocos2d::Object *target, SEL_MovementEventCallFunc callFunc);
|
CC_DEPRECATED_ATTRIBUTE void setMovementEventCallFunc(cocos2d::Object *target, SEL_MovementEventCallFunc callFunc);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Set armature's frame event callback function
|
* Set armature's frame event callback function
|
||||||
* To disconnect this event, just setFrameEventCallFunc(nullptr, nullptr);
|
* To disconnect this event, just setFrameEventCallFunc(nullptr, nullptr);
|
||||||
*/
|
*/
|
||||||
void setFrameEventCallFunc(cocos2d::Object *target, SEL_FrameEventCallFunc callFunc);
|
CC_DEPRECATED_ATTRIBUTE void setFrameEventCallFunc(cocos2d::Object *target, SEL_FrameEventCallFunc callFunc);
|
||||||
|
|
||||||
|
void setMovementEventCallFunc(std::function<void(Armature *armature, MovementEventType movementType, const char *movementID)> listener);
|
||||||
|
void setFrameEventCallFunc(std::function<void(Bone *bone, const char *frameEventName, int originFrameIndex, int currentFrameIndex)> listener);
|
||||||
|
|
||||||
virtual void setAnimationData(AnimationData *data)
|
virtual void setAnimationData(AnimationData *data)
|
||||||
{
|
{
|
||||||
|
@ -255,6 +256,13 @@ protected:
|
||||||
*/
|
*/
|
||||||
void frameEvent(Bone *bone, const char *frameEventName, int originFrameIndex, int currentFrameIndex);
|
void frameEvent(Bone *bone, const char *frameEventName, int originFrameIndex, int currentFrameIndex);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Emit a movement event
|
||||||
|
*/
|
||||||
|
void movementEvent(Armature *armature, MovementEventType movementType, const char *movementID);
|
||||||
|
|
||||||
|
void updateMovementList();
|
||||||
|
|
||||||
bool isIgnoreFrameEvent() const { return _ignoreFrameEvent; }
|
bool isIgnoreFrameEvent() const { return _ignoreFrameEvent; }
|
||||||
|
|
||||||
friend class Tween;
|
friend class Tween;
|
||||||
|
@ -273,11 +281,19 @@ protected:
|
||||||
|
|
||||||
int _toIndex; //! The frame index in MovementData->m_pMovFrameDataArr, it's different from m_iFrameIndex.
|
int _toIndex; //! The frame index in MovementData->m_pMovFrameDataArr, it's different from m_iFrameIndex.
|
||||||
|
|
||||||
cocos2d::Array *_tweenList;
|
cocos2d::Vector<Tween*> _tweenList;
|
||||||
|
|
||||||
bool _ignoreFrameEvent;
|
bool _ignoreFrameEvent;
|
||||||
|
|
||||||
std::queue<FrameEvent*> _frameEventQueue;
|
std::queue<FrameEvent*> _frameEventQueue;
|
||||||
|
std::queue<MovementEvent*> _movementEventQueue;
|
||||||
|
|
||||||
|
std::vector<std::string> _movementList;
|
||||||
|
|
||||||
|
bool _onMovementList;
|
||||||
|
bool _movementListLoop;
|
||||||
|
unsigned int _movementIndex;
|
||||||
|
int _movementListDurationTo;
|
||||||
|
|
||||||
cocos2d::Object *_userObject;
|
cocos2d::Object *_userObject;
|
||||||
protected:
|
protected:
|
||||||
|
@ -301,6 +317,10 @@ protected:
|
||||||
|
|
||||||
cocos2d::Object *_movementEventTarget;
|
cocos2d::Object *_movementEventTarget;
|
||||||
cocos2d::Object *_frameEventTarget;
|
cocos2d::Object *_frameEventTarget;
|
||||||
|
|
||||||
|
|
||||||
|
std::function<void(Armature *armature, MovementEventType movementType, const char *movementID)> _movementEventListener;
|
||||||
|
std::function<void(Bone *bone, const char *frameEventName, int originFrameIndex, int currentFrameIndex)> _frameEventListener;
|
||||||
};
|
};
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -56,34 +56,20 @@ void ArmatureDataManager::destoryInstance()
|
||||||
|
|
||||||
ArmatureDataManager::ArmatureDataManager(void)
|
ArmatureDataManager::ArmatureDataManager(void)
|
||||||
{
|
{
|
||||||
_armarureDatas = nullptr;
|
_armarureDatas.clear();
|
||||||
_animationDatas = nullptr;
|
_animationDatas.clear();
|
||||||
_textureDatas = nullptr;
|
_textureDatas.clear();
|
||||||
_autoLoadSpriteFile = false;
|
_autoLoadSpriteFile = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
ArmatureDataManager::~ArmatureDataManager(void)
|
ArmatureDataManager::~ArmatureDataManager(void)
|
||||||
{
|
{
|
||||||
if( _animationDatas )
|
_animationDatas.clear();
|
||||||
{
|
_armarureDatas.clear();
|
||||||
_animationDatas->removeAllObjects();
|
_textureDatas.clear();
|
||||||
}
|
|
||||||
if( _armarureDatas )
|
|
||||||
{
|
|
||||||
_armarureDatas->removeAllObjects();
|
|
||||||
}
|
|
||||||
|
|
||||||
if( _textureDatas )
|
|
||||||
{
|
|
||||||
_textureDatas->removeAllObjects();
|
|
||||||
}
|
|
||||||
|
|
||||||
_relativeDatas.clear();
|
_relativeDatas.clear();
|
||||||
|
|
||||||
CC_SAFE_DELETE(_animationDatas);
|
|
||||||
CC_SAFE_DELETE(_armarureDatas);
|
|
||||||
CC_SAFE_DELETE(_textureDatas);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -92,17 +78,9 @@ bool ArmatureDataManager::init()
|
||||||
bool bRet = false;
|
bool bRet = false;
|
||||||
do
|
do
|
||||||
{
|
{
|
||||||
_armarureDatas = Dictionary::create();
|
_armarureDatas.clear();
|
||||||
CCASSERT(_armarureDatas, "create ArmatureDataManager::_armarureDatas fail!");
|
_animationDatas.clear();
|
||||||
_armarureDatas->retain();
|
_textureDatas.clear();
|
||||||
|
|
||||||
_animationDatas = Dictionary::create();
|
|
||||||
CCASSERT(_animationDatas, "create ArmatureDataManager::_animationDatas fail!");
|
|
||||||
_animationDatas->retain();
|
|
||||||
|
|
||||||
_textureDatas = Dictionary::create();
|
|
||||||
CCASSERT(_textureDatas, "create ArmatureDataManager::_textureDatas fail!");
|
|
||||||
_textureDatas->retain();
|
|
||||||
|
|
||||||
bRet = true;
|
bRet = true;
|
||||||
}
|
}
|
||||||
|
@ -143,97 +121,70 @@ void ArmatureDataManager::removeArmatureFileInfo(const char *configFilePath)
|
||||||
|
|
||||||
void ArmatureDataManager::addArmatureData(const char *id, ArmatureData *armatureData, const char *configFilePath)
|
void ArmatureDataManager::addArmatureData(const char *id, ArmatureData *armatureData, const char *configFilePath)
|
||||||
{
|
{
|
||||||
if(_armarureDatas)
|
|
||||||
{
|
|
||||||
if (RelativeData *data = getRelativeData(configFilePath))
|
if (RelativeData *data = getRelativeData(configFilePath))
|
||||||
{
|
{
|
||||||
data->armatures.push_back(id);
|
data->armatures.push_back(id);
|
||||||
}
|
}
|
||||||
|
|
||||||
_armarureDatas->setObject(armatureData, id);
|
_armarureDatas.insert(id, armatureData);
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
ArmatureData *ArmatureDataManager::getArmatureData(const char *id)
|
ArmatureData *ArmatureDataManager::getArmatureData(const char *id)
|
||||||
{
|
{
|
||||||
ArmatureData *armatureData = nullptr;
|
ArmatureData *armatureData = nullptr;
|
||||||
if (_armarureDatas)
|
armatureData = (ArmatureData *)_armarureDatas.at(id);
|
||||||
{
|
|
||||||
armatureData = (ArmatureData *)_armarureDatas->objectForKey(id);
|
|
||||||
}
|
|
||||||
return armatureData;
|
return armatureData;
|
||||||
}
|
}
|
||||||
|
|
||||||
void ArmatureDataManager::removeArmatureData(const char *id)
|
void ArmatureDataManager::removeArmatureData(const char *id)
|
||||||
{
|
{
|
||||||
if (_armarureDatas)
|
_armarureDatas.erase(id);
|
||||||
{
|
|
||||||
_armarureDatas->removeObjectForKey(id);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void ArmatureDataManager::addAnimationData(const char *id, AnimationData *animationData, const char *configFilePath)
|
void ArmatureDataManager::addAnimationData(const char *id, AnimationData *animationData, const char *configFilePath)
|
||||||
{
|
{
|
||||||
if(_animationDatas)
|
|
||||||
{
|
|
||||||
if (RelativeData *data = getRelativeData(configFilePath))
|
if (RelativeData *data = getRelativeData(configFilePath))
|
||||||
{
|
{
|
||||||
data->animations.push_back(id);
|
data->animations.push_back(id);
|
||||||
}
|
}
|
||||||
|
|
||||||
_animationDatas->setObject(animationData, id);
|
_animationDatas.insert(id, animationData);
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
AnimationData *ArmatureDataManager::getAnimationData(const char *id)
|
AnimationData *ArmatureDataManager::getAnimationData(const char *id)
|
||||||
{
|
{
|
||||||
AnimationData *animationData = nullptr;
|
AnimationData *animationData = nullptr;
|
||||||
if (_animationDatas)
|
animationData = (AnimationData *)_animationDatas.at(id);
|
||||||
{
|
|
||||||
animationData = (AnimationData *)_animationDatas->objectForKey(id);
|
|
||||||
}
|
|
||||||
return animationData;
|
return animationData;
|
||||||
}
|
}
|
||||||
|
|
||||||
void ArmatureDataManager::removeAnimationData(const char *id)
|
void ArmatureDataManager::removeAnimationData(const char *id)
|
||||||
{
|
{
|
||||||
if (_animationDatas)
|
_animationDatas.erase(id);
|
||||||
{
|
|
||||||
_animationDatas->removeObjectForKey(id);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void ArmatureDataManager::addTextureData(const char *id, TextureData *textureData, const char *configFilePath)
|
void ArmatureDataManager::addTextureData(const char *id, TextureData *textureData, const char *configFilePath)
|
||||||
{
|
{
|
||||||
if(_textureDatas)
|
|
||||||
{
|
|
||||||
if (RelativeData *data = getRelativeData(configFilePath))
|
if (RelativeData *data = getRelativeData(configFilePath))
|
||||||
{
|
{
|
||||||
data->textures.push_back(id);
|
data->textures.push_back(id);
|
||||||
}
|
}
|
||||||
|
|
||||||
_textureDatas->setObject(textureData, id);
|
_textureDatas.insert(id, textureData);
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
TextureData *ArmatureDataManager::getTextureData(const char *id)
|
TextureData *ArmatureDataManager::getTextureData(const char *id)
|
||||||
{
|
{
|
||||||
TextureData *textureData = nullptr;
|
TextureData *textureData = nullptr;
|
||||||
if (_textureDatas)
|
textureData = (TextureData *)_textureDatas.at(id);
|
||||||
{
|
|
||||||
textureData = (TextureData *)_textureDatas->objectForKey(id);
|
|
||||||
}
|
|
||||||
return textureData;
|
return textureData;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
void ArmatureDataManager::removeTextureData(const char *id)
|
void ArmatureDataManager::removeTextureData(const char *id)
|
||||||
{
|
{
|
||||||
if(_textureDatas)
|
_textureDatas.erase(id);
|
||||||
{
|
|
||||||
_textureDatas->removeObjectForKey(id);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void ArmatureDataManager::addArmatureFileInfo(const char *configFilePath)
|
void ArmatureDataManager::addArmatureFileInfo(const char *configFilePath)
|
||||||
|
@ -285,15 +236,15 @@ bool ArmatureDataManager::isAutoLoadSpriteFile()
|
||||||
return _autoLoadSpriteFile;
|
return _autoLoadSpriteFile;
|
||||||
}
|
}
|
||||||
|
|
||||||
Dictionary *ArmatureDataManager::getArmatureDatas() const
|
const cocos2d::Map<std::string, ArmatureData*>& ArmatureDataManager::getArmatureDatas() const
|
||||||
{
|
{
|
||||||
return _armarureDatas;
|
return _armarureDatas;
|
||||||
}
|
}
|
||||||
Dictionary *ArmatureDataManager::getAnimationDatas() const
|
const cocos2d::Map<std::string, AnimationData*>& ArmatureDataManager::getAnimationDatas() const
|
||||||
{
|
{
|
||||||
return _animationDatas;
|
return _animationDatas;
|
||||||
}
|
}
|
||||||
Dictionary *ArmatureDataManager::getTextureDatas() const
|
const cocos2d::Map<std::string, TextureData*>& ArmatureDataManager::getTextureDatas() const
|
||||||
{
|
{
|
||||||
return _textureDatas;
|
return _textureDatas;
|
||||||
}
|
}
|
||||||
|
|
|
@ -168,9 +168,9 @@ public:
|
||||||
bool isAutoLoadSpriteFile();
|
bool isAutoLoadSpriteFile();
|
||||||
|
|
||||||
|
|
||||||
cocos2d::Dictionary *getArmatureDatas() const;
|
const cocos2d::Map<std::string, ArmatureData*>& getArmatureDatas() const;
|
||||||
cocos2d::Dictionary *getAnimationDatas() const;
|
const cocos2d::Map<std::string, AnimationData*>& getAnimationDatas() const;
|
||||||
cocos2d::Dictionary *getTextureDatas() const;
|
const cocos2d::Map<std::string, TextureData*>& getTextureDatas() const;
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
void addRelativeData(const char* configFilePath);
|
void addRelativeData(const char* configFilePath);
|
||||||
|
@ -181,21 +181,21 @@ private:
|
||||||
* @key std::string
|
* @key std::string
|
||||||
* @value ArmatureData *
|
* @value ArmatureData *
|
||||||
*/
|
*/
|
||||||
cocos2d::Dictionary *_armarureDatas;
|
cocos2d::Map<std::string, ArmatureData*> _armarureDatas;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief save animation datas
|
* @brief save animation datas
|
||||||
* @key std::string
|
* @key std::string
|
||||||
* @value AnimationData *
|
* @value AnimationData *
|
||||||
*/
|
*/
|
||||||
cocos2d::Dictionary *_animationDatas;
|
cocos2d::Map<std::string, AnimationData*> _animationDatas;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief save texture datas
|
* @brief save texture datas
|
||||||
* @key std::string
|
* @key std::string
|
||||||
* @value TextureData *
|
* @value TextureData *
|
||||||
*/
|
*/
|
||||||
cocos2d::Dictionary *_textureDatas;
|
cocos2d::Map<std::string, TextureData*> _textureDatas;
|
||||||
|
|
||||||
bool _autoLoadSpriteFile;
|
bool _autoLoadSpriteFile;
|
||||||
|
|
||||||
|
|
|
@ -28,7 +28,7 @@ namespace cocostudio {
|
||||||
|
|
||||||
const char *armatureVersion()
|
const char *armatureVersion()
|
||||||
{
|
{
|
||||||
return "1.0.0.0";
|
return "1.1.0.0";
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -42,11 +42,11 @@ THE SOFTWARE.
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#ifndef ENABLE_PHYSICS_CHIPMUNK_DETECT
|
#ifndef ENABLE_PHYSICS_CHIPMUNK_DETECT
|
||||||
#define ENABLE_PHYSICS_CHIPMUNK_DETECT 1
|
#define ENABLE_PHYSICS_CHIPMUNK_DETECT 0
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#ifndef ENABLE_PHYSICS_SAVE_CALCULATED_VERTEX
|
#ifndef ENABLE_PHYSICS_SAVE_CALCULATED_VERTEX
|
||||||
#define ENABLE_PHYSICS_SAVE_CALCULATED_VERTEX 0
|
#define ENABLE_PHYSICS_SAVE_CALCULATED_VERTEX 1
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#define CS_RETURN_IF(cond) if (cond) return
|
#define CS_RETURN_IF(cond) if (cond) return
|
||||||
|
|
|
@ -74,7 +74,8 @@ Bone::Bone()
|
||||||
// _worldTransform = AffineTransformMake(1, 0, 0, 1, 0, 0);
|
// _worldTransform = AffineTransformMake(1, 0, 0, 1, 0, 0);
|
||||||
kmMat4Identity(&_worldTransform);
|
kmMat4Identity(&_worldTransform);
|
||||||
_boneTransformDirty = true;
|
_boneTransformDirty = true;
|
||||||
_blendType = BLEND_NORMAL;
|
_blendFunc = BlendFunc::ALPHA_NON_PREMULTIPLIED;
|
||||||
|
_blendDirty = false;
|
||||||
_worldInfo = nullptr;
|
_worldInfo = nullptr;
|
||||||
|
|
||||||
_armatureParentBone = nullptr;
|
_armatureParentBone = nullptr;
|
||||||
|
@ -228,7 +229,8 @@ void Bone::update(float delta)
|
||||||
|
|
||||||
DisplayFactory::updateDisplay(this, delta, _boneTransformDirty || _armature->getArmatureTransformDirty());
|
DisplayFactory::updateDisplay(this, delta, _boneTransformDirty || _armature->getArmatureTransformDirty());
|
||||||
|
|
||||||
std::for_each(_children.begin(), _children.end(), [&delta](Node* obj){
|
std::for_each(_children.begin(), _children.end(), [&delta](Node* obj)
|
||||||
|
{
|
||||||
Bone *childBone = static_cast<Bone*>(obj);
|
Bone *childBone = static_cast<Bone*>(obj);
|
||||||
childBone->update(delta);
|
childBone->update(delta);
|
||||||
});
|
});
|
||||||
|
@ -249,6 +251,15 @@ void Bone::applyParentTransform(Bone *parent)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
void CCBone::setBlendFunc(const BlendFunc& blendFunc)
|
||||||
|
{
|
||||||
|
if (_blendFunc.src != blendFunc.src && _blendFunc.dst != blendFunc.dst)
|
||||||
|
{
|
||||||
|
_blendFunc = blendFunc;
|
||||||
|
_blendDirty = true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
void Bone::updateDisplayedColor(const Color3B &parentColor)
|
void Bone::updateDisplayedColor(const Color3B &parentColor)
|
||||||
{
|
{
|
||||||
_realColor = Color3B(255, 255, 255);
|
_realColor = Color3B(255, 255, 255);
|
||||||
|
@ -429,25 +440,31 @@ void Bone::changeDisplayByIndex(int index, bool force)
|
||||||
_displayManager->changeDisplayByIndex(index, force);
|
_displayManager->changeDisplayByIndex(index, force);
|
||||||
}
|
}
|
||||||
|
|
||||||
Array *Bone::getColliderBodyList()
|
|
||||||
|
void Bone::changeDisplayByName(const char *name, bool force)
|
||||||
|
{
|
||||||
|
_displayManager->changeDisplayByName(name, force);
|
||||||
|
}
|
||||||
|
|
||||||
|
ColliderDetector* Bone::getColliderDetector() const
|
||||||
{
|
{
|
||||||
if (DecorativeDisplay *decoDisplay = _displayManager->getCurrentDecorativeDisplay())
|
if (DecorativeDisplay *decoDisplay = _displayManager->getCurrentDecorativeDisplay())
|
||||||
{
|
{
|
||||||
if (ColliderDetector *detector = decoDisplay->getColliderDetector())
|
if (ColliderDetector *detector = decoDisplay->getColliderDetector())
|
||||||
{
|
{
|
||||||
return detector->getColliderBodyList();
|
return detector;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return nullptr;
|
return nullptr;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
#if ENABLE_PHYSICS_BOX2D_DETECT || ENABLE_PHYSICS_CHIPMUNK_DETECT
|
||||||
void Bone::setColliderFilter(ColliderFilter *filter)
|
void Bone::setColliderFilter(ColliderFilter *filter)
|
||||||
{
|
{
|
||||||
Array *array = _displayManager->getDecorativeDisplayList();
|
auto array = _displayManager->getDecorativeDisplayList();
|
||||||
|
|
||||||
for(auto object : *array)
|
for(auto& object : array)
|
||||||
{
|
{
|
||||||
DecorativeDisplay *decoDisplay = static_cast<DecorativeDisplay *>(object);
|
DecorativeDisplay *decoDisplay = static_cast<DecorativeDisplay *>(object);
|
||||||
if (ColliderDetector *detector = decoDisplay->getColliderDetector())
|
if (ColliderDetector *detector = decoDisplay->getColliderDetector())
|
||||||
|
@ -467,6 +484,6 @@ ColliderFilter *Bone::getColliderFilter()
|
||||||
}
|
}
|
||||||
return nullptr;
|
return nullptr;
|
||||||
}
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -92,6 +92,7 @@ public:
|
||||||
void removeDisplay(int index);
|
void removeDisplay(int index);
|
||||||
|
|
||||||
void changeDisplayByIndex(int index, bool force);
|
void changeDisplayByIndex(int index, bool force);
|
||||||
|
void changeDisplayByName(const char *name, bool force);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Add a child to this bone, and it will let this child call setParent(Bone *parent) function to set self to it's parent
|
* Add a child to this bone, and it will let this child call setParent(Bone *parent) function to set self to it's parent
|
||||||
|
@ -161,10 +162,12 @@ public:
|
||||||
/*
|
/*
|
||||||
* Get the ColliderBody list in this bone. The object in the Array is ColliderBody.
|
* Get the ColliderBody list in this bone. The object in the Array is ColliderBody.
|
||||||
*/
|
*/
|
||||||
virtual cocos2d::Array *getColliderBodyList();
|
virtual ColliderDetector* getColliderDetector() const;
|
||||||
|
|
||||||
|
#if ENABLE_PHYSICS_BOX2D_DETECT || ENABLE_PHYSICS_CHIPMUNK_DETECT
|
||||||
virtual void setColliderFilter(ColliderFilter *filter);
|
virtual void setColliderFilter(ColliderFilter *filter);
|
||||||
virtual ColliderFilter *getColliderFilter();
|
virtual ColliderFilter *getColliderFilter();
|
||||||
|
#endif
|
||||||
|
|
||||||
virtual void setBoneData(BoneData *boneData);
|
virtual void setBoneData(BoneData *boneData);
|
||||||
virtual BoneData *getBoneData() const;
|
virtual BoneData *getBoneData() const;
|
||||||
|
@ -188,8 +191,18 @@ public:
|
||||||
*/
|
*/
|
||||||
CC_DEPRECATED_ATTRIBUTE virtual bool getIgnoreMovementBoneData() const { return isIgnoreMovementBoneData(); }
|
CC_DEPRECATED_ATTRIBUTE virtual bool getIgnoreMovementBoneData() const { return isIgnoreMovementBoneData(); }
|
||||||
|
|
||||||
virtual void setBlendType(BlendType type) { _blendType = type; }
|
|
||||||
virtual BlendType getBlendType() const { return _blendType; }
|
/*
|
||||||
|
* Set blend function
|
||||||
|
*/
|
||||||
|
virtual void setBlendFunc(const cocos2d::BlendFunc& blendFunc);
|
||||||
|
virtual cocos2d::BlendFunc getBlendFunc(void) { return _blendFunc; }
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Set if blend function is dirty
|
||||||
|
*/
|
||||||
|
virtual void setBlendDirty(bool dirty) { _blendDirty = dirty; }
|
||||||
|
virtual bool isBlendDirty(void) { return _blendDirty; }
|
||||||
|
|
||||||
virtual FrameData *getTweenData() const { return _tweenData; }
|
virtual FrameData *getTweenData() const { return _tweenData; }
|
||||||
|
|
||||||
|
@ -220,7 +233,8 @@ protected:
|
||||||
*/
|
*/
|
||||||
bool _ignoreMovementBoneData;
|
bool _ignoreMovementBoneData;
|
||||||
|
|
||||||
BlendType _blendType;
|
cocos2d::BlendFunc _blendFunc;
|
||||||
|
bool _blendDirty;
|
||||||
|
|
||||||
Tween *_tween; //! Calculate tween effect
|
Tween *_tween; //! Calculate tween effect
|
||||||
|
|
||||||
|
|
|
@ -26,11 +26,7 @@ THE SOFTWARE.
|
||||||
#include "cocostudio/CCBone.h"
|
#include "cocostudio/CCBone.h"
|
||||||
#include "cocostudio/CCTransformHelp.h"
|
#include "cocostudio/CCTransformHelp.h"
|
||||||
|
|
||||||
#if ENABLE_PHYSICS_BOX2D_DETECT
|
|
||||||
#include "Box2D/Box2D.h"
|
|
||||||
#elif ENABLE_PHYSICS_CHIPMUNK_DETECT
|
|
||||||
#include "chipmunk.h"
|
|
||||||
#endif
|
|
||||||
|
|
||||||
using namespace cocos2d;
|
using namespace cocos2d;
|
||||||
|
|
||||||
|
@ -38,7 +34,7 @@ namespace cocostudio {
|
||||||
|
|
||||||
|
|
||||||
#if ENABLE_PHYSICS_BOX2D_DETECT
|
#if ENABLE_PHYSICS_BOX2D_DETECT
|
||||||
ColliderFilter::ColliderFilter(unsigned short categoryBits, unsigned short maskBits, signed short groupIndex)
|
ColliderFilter::ColliderFilter(uint16 categoryBits, uint16 maskBits, int16 groupIndex)
|
||||||
: _categoryBits(categoryBits)
|
: _categoryBits(categoryBits)
|
||||||
, _maskBits(maskBits)
|
, _maskBits(maskBits)
|
||||||
, _groupIndex(groupIndex)
|
, _groupIndex(groupIndex)
|
||||||
|
@ -56,7 +52,7 @@ void ColliderFilter::updateShape(b2Fixture *fixture)
|
||||||
}
|
}
|
||||||
|
|
||||||
#elif ENABLE_PHYSICS_CHIPMUNK_DETECT
|
#elif ENABLE_PHYSICS_CHIPMUNK_DETECT
|
||||||
ColliderFilter::ColliderFilter(uintptr_t collisionType, uintptr_t group)
|
ColliderFilter::ColliderFilter(cpCollisionType collisionType, cpGroup group)
|
||||||
: _collisionType(collisionType)
|
: _collisionType(collisionType)
|
||||||
, _group(group)
|
, _group(group)
|
||||||
{
|
{
|
||||||
|
@ -95,18 +91,24 @@ ColliderBody::ColliderBody(ContourData *contourData)
|
||||||
CC_SAFE_RETAIN(_calculatedVertexList);
|
CC_SAFE_RETAIN(_calculatedVertexList);
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
#elif ENABLE_PHYSICS_SAVE_CALCULATED_VERTEX
|
||||||
|
ColliderBody::ColliderBody(ContourData *contourData)
|
||||||
|
: _contourData(contourData)
|
||||||
|
{
|
||||||
|
CC_SAFE_RETAIN(_contourData);
|
||||||
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
ColliderBody::~ColliderBody()
|
ColliderBody::~ColliderBody()
|
||||||
{
|
{
|
||||||
CC_SAFE_RELEASE(_contourData);
|
CC_SAFE_RELEASE(_contourData);
|
||||||
CC_SAFE_DELETE(_filter);
|
|
||||||
|
|
||||||
#if ENABLE_PHYSICS_SAVE_CALCULATED_VERTEX
|
#if ENABLE_PHYSICS_BOX2D_DETECT || ENABLE_PHYSICS_CHIPMUNK_DETECT
|
||||||
CC_SAFE_RELEASE(_calculatedVertexList);
|
CC_SAFE_DELETE(_filter);
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#if ENABLE_PHYSICS_BOX2D_DETECT || ENABLE_PHYSICS_CHIPMUNK_DETECT
|
||||||
void ColliderBody::setColliderFilter(ColliderFilter *filter)
|
void ColliderBody::setColliderFilter(ColliderFilter *filter)
|
||||||
{
|
{
|
||||||
*_filter = *filter;
|
*_filter = *filter;
|
||||||
|
@ -115,6 +117,7 @@ ColliderFilter *ColliderBody::getColliderFilter()
|
||||||
{
|
{
|
||||||
return _filter;
|
return _filter;
|
||||||
}
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
@ -143,27 +146,30 @@ ColliderDetector *ColliderDetector::create(Bone *bone)
|
||||||
}
|
}
|
||||||
|
|
||||||
ColliderDetector::ColliderDetector()
|
ColliderDetector::ColliderDetector()
|
||||||
: _colliderBodyList(nullptr)
|
: _active(false)
|
||||||
, _filter(nullptr)
|
|
||||||
, _active(false)
|
|
||||||
{
|
{
|
||||||
|
#if ENABLE_PHYSICS_BOX2D_DETECT || ENABLE_PHYSICS_CHIPMUNK_DETECT
|
||||||
_body = nullptr;
|
_body = nullptr;
|
||||||
|
_filter = nullptr;
|
||||||
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
ColliderDetector::~ColliderDetector()
|
ColliderDetector::~ColliderDetector()
|
||||||
{
|
{
|
||||||
_colliderBodyList->removeAllObjects();
|
_colliderBodyList.clear();
|
||||||
CC_SAFE_DELETE(_colliderBodyList);
|
|
||||||
|
#if ENABLE_PHYSICS_BOX2D_DETECT || ENABLE_PHYSICS_CHIPMUNK_DETECT
|
||||||
CC_SAFE_DELETE(_filter);
|
CC_SAFE_DELETE(_filter);
|
||||||
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
bool ColliderDetector::init()
|
bool ColliderDetector::init()
|
||||||
{
|
{
|
||||||
_colliderBodyList = Array::create();
|
_colliderBodyList.clear();
|
||||||
CCASSERT(_colliderBodyList, "create _colliderBodyList failed!");
|
|
||||||
_colliderBodyList->retain();
|
|
||||||
|
|
||||||
|
#if ENABLE_PHYSICS_BOX2D_DETECT || ENABLE_PHYSICS_CHIPMUNK_DETECT
|
||||||
_filter = new ColliderFilter();
|
_filter = new ColliderFilter();
|
||||||
|
#endif
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
@ -179,46 +185,50 @@ bool ColliderDetector::init(Bone *bone)
|
||||||
void ColliderDetector::addContourData(ContourData *contourData)
|
void ColliderDetector::addContourData(ContourData *contourData)
|
||||||
{
|
{
|
||||||
ColliderBody *colliderBody = new ColliderBody(contourData);
|
ColliderBody *colliderBody = new ColliderBody(contourData);
|
||||||
_colliderBodyList->addObject(colliderBody);
|
_colliderBodyList.pushBack(colliderBody);
|
||||||
colliderBody->release();
|
colliderBody->release();
|
||||||
|
|
||||||
|
|
||||||
#if ENABLE_PHYSICS_SAVE_CALCULATED_VERTEX
|
#if ENABLE_PHYSICS_SAVE_CALCULATED_VERTEX
|
||||||
CCArray *calculatedVertexList = colliderBody->getCalculatedVertexList();
|
std::vector<Point> &calculatedVertexList = colliderBody->_calculatedVertexList;
|
||||||
|
|
||||||
int num = contourData->vertexList.size();
|
unsigned long num = contourData->vertexList.size();
|
||||||
for (int i = 0; i < num; i++)
|
for (unsigned long i = 0; i < num; i++)
|
||||||
{
|
{
|
||||||
ContourVertex2 *newVertex = new ContourVertex2(0, 0);
|
calculatedVertexList.push_back(Point());
|
||||||
calculatedVertexList->addObject(newVertex);
|
|
||||||
newVertex->release();
|
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
void ColliderDetector::addContourDataList(Array *contourDataList)
|
void ColliderDetector::addContourDataList(cocos2d::Vector<ContourData*> &contourDataList)
|
||||||
{
|
{
|
||||||
for(auto object : *contourDataList)
|
for_each(contourDataList.begin(), contourDataList.end(), [this](ContourData *contourData)
|
||||||
{
|
{
|
||||||
addContourData((ContourData *)object);
|
this->addContourData(contourData);
|
||||||
}
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
void ColliderDetector::removeContourData(ContourData *contourData)
|
void ColliderDetector::removeContourData(ContourData *contourData)
|
||||||
{
|
{
|
||||||
for(auto object : *_colliderBodyList)
|
std::vector<ColliderBody*> eraseList;
|
||||||
|
|
||||||
|
for_each(_colliderBodyList.begin(), _colliderBodyList.end(), [&contourData, this, &eraseList](ColliderBody *body)
|
||||||
{
|
{
|
||||||
ColliderBody *body = (ColliderBody*)object;
|
|
||||||
if (body && body->getContourData() == contourData)
|
if (body && body->getContourData() == contourData)
|
||||||
{
|
{
|
||||||
_colliderBodyList->removeObject(body);
|
eraseList.push_back(body);
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
for_each(eraseList.begin(), eraseList.end(), [this](ColliderBody *body)
|
||||||
|
{
|
||||||
|
this->_colliderBodyList.eraseObject(body);
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
void ColliderDetector::removeAll()
|
void ColliderDetector::removeAll()
|
||||||
{
|
{
|
||||||
_colliderBodyList->removeAllObjects();
|
_colliderBodyList.clear();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -240,7 +250,7 @@ void ColliderDetector::setActive(bool active)
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
for(auto object : *_colliderBodyList)
|
for(auto& object : _colliderBodyList)
|
||||||
{
|
{
|
||||||
ColliderBody *colliderBody = (ColliderBody *)object;
|
ColliderBody *colliderBody = (ColliderBody *)object;
|
||||||
b2Fixture *fixture = colliderBody->getB2Fixture();
|
b2Fixture *fixture = colliderBody->getB2Fixture();
|
||||||
|
@ -255,7 +265,7 @@ void ColliderDetector::setActive(bool active)
|
||||||
{
|
{
|
||||||
if (_active)
|
if (_active)
|
||||||
{
|
{
|
||||||
for(auto object : *_colliderBodyList)
|
for(auto& object : _colliderBodyList)
|
||||||
{
|
{
|
||||||
ColliderBody *colliderBody = (ColliderBody *)object;
|
ColliderBody *colliderBody = (ColliderBody *)object;
|
||||||
cpShape *shape = colliderBody->getShape();
|
cpShape *shape = colliderBody->getShape();
|
||||||
|
@ -267,7 +277,7 @@ void ColliderDetector::setActive(bool active)
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
for(auto object : *_colliderBodyList)
|
for(auto& object : _colliderBodyList)
|
||||||
{
|
{
|
||||||
ColliderBody *colliderBody = (ColliderBody *)object;
|
ColliderBody *colliderBody = (ColliderBody *)object;
|
||||||
cpShape *shape = colliderBody->getShape();
|
cpShape *shape = colliderBody->getShape();
|
||||||
|
@ -286,16 +296,18 @@ bool ColliderDetector::getActive()
|
||||||
return _active;
|
return _active;
|
||||||
}
|
}
|
||||||
|
|
||||||
Array *ColliderDetector::getColliderBodyList()
|
const cocos2d::Vector<ColliderBody*>& ColliderDetector::getColliderBodyList()
|
||||||
{
|
{
|
||||||
return _colliderBodyList;
|
return _colliderBodyList;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
#if ENABLE_PHYSICS_BOX2D_DETECT || ENABLE_PHYSICS_CHIPMUNK_DETECT
|
||||||
void ColliderDetector::setColliderFilter(ColliderFilter *filter)
|
void ColliderDetector::setColliderFilter(ColliderFilter *filter)
|
||||||
{
|
{
|
||||||
*_filter = *filter;
|
*_filter = *filter;
|
||||||
|
|
||||||
for(auto object : *_colliderBodyList)
|
for(auto& object : _colliderBodyList)
|
||||||
{
|
{
|
||||||
ColliderBody *colliderBody = (ColliderBody *)object;
|
ColliderBody *colliderBody = (ColliderBody *)object;
|
||||||
colliderBody->setColliderFilter(filter);
|
colliderBody->setColliderFilter(filter);
|
||||||
|
@ -317,6 +329,7 @@ ColliderFilter *ColliderDetector::getColliderFilter()
|
||||||
{
|
{
|
||||||
return _filter;
|
return _filter;
|
||||||
}
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
|
|
||||||
Point helpPoint;
|
Point helpPoint;
|
||||||
|
@ -328,7 +341,7 @@ void ColliderDetector::updateTransform(kmMat4 &t)
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
for(auto object : *_colliderBodyList)
|
for(auto& object : _colliderBodyList)
|
||||||
{
|
{
|
||||||
ColliderBody *colliderBody = (ColliderBody *)object;
|
ColliderBody *colliderBody = (ColliderBody *)object;
|
||||||
ContourData *contourData = colliderBody->getContourData();
|
ContourData *contourData = colliderBody->getContourData();
|
||||||
|
@ -347,22 +360,22 @@ void ColliderDetector::updateTransform(kmMat4 &t)
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
int num = contourData->vertexList.count();
|
unsigned long num = contourData->vertexList.size();
|
||||||
ContourVertex2 **vs = (ContourVertex2 **)contourData->vertexList.data->arr;
|
std::vector<cocos2d::Point> &vs = contourData->vertexList;
|
||||||
|
|
||||||
#if ENABLE_PHYSICS_SAVE_CALCULATED_VERTEX
|
#if ENABLE_PHYSICS_SAVE_CALCULATED_VERTEX
|
||||||
ContourVertex2 **cvs = (ContourVertex2 **)colliderBody->getCalculatedVertexList()->data->arr;
|
std::vector<cocos2d::Point> &cvs = colliderBody->_calculatedVertexList;
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
for (int i = 0; i < num; i++)
|
for (unsigned long i = 0; i < num; i++)
|
||||||
{
|
{
|
||||||
helpPoint.setPoint( vs[i]->x, vs[i]->y);
|
helpPoint.setPoint( vs.at(i).x, vs.at(i).y);
|
||||||
helpPoint = PointApplyTransform(helpPoint, t);
|
helpPoint = PointApplyTransform(helpPoint, t);
|
||||||
|
|
||||||
|
|
||||||
#if ENABLE_PHYSICS_SAVE_CALCULATED_VERTEX
|
#if ENABLE_PHYSICS_SAVE_CALCULATED_VERTEX
|
||||||
cvs[i]->x = helpPoint.x;
|
cvs.at(i).x = helpPoint.x;
|
||||||
cvs[i]->y = helpPoint.y;
|
cvs.at(i).y = helpPoint.y;
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#if ENABLE_PHYSICS_BOX2D_DETECT
|
#if ENABLE_PHYSICS_BOX2D_DETECT
|
||||||
|
@ -383,8 +396,8 @@ void ColliderDetector::updateTransform(kmMat4 &t)
|
||||||
}
|
}
|
||||||
|
|
||||||
#if ENABLE_PHYSICS_CHIPMUNK_DETECT
|
#if ENABLE_PHYSICS_CHIPMUNK_DETECT
|
||||||
cpConvexHull(num, shape->verts, nullptr, nullptr, 0);
|
cpConvexHull((int)num, shape->verts, nullptr, nullptr, 0);
|
||||||
for (int i = 0; i < num; i++)
|
for (unsigned long i = 0; i < num; i++)
|
||||||
{
|
{
|
||||||
cpVect b = shape->verts[(i + 1) % shape->numVerts];
|
cpVect b = shape->verts[(i + 1) % shape->numVerts];
|
||||||
cpVect n = cpvnormalize(cpvperp(cpvsub(b, shape->verts[i])));
|
cpVect n = cpvnormalize(cpvperp(cpvsub(b, shape->verts[i])));
|
||||||
|
@ -402,26 +415,23 @@ void ColliderDetector::setBody(b2Body *pBody)
|
||||||
{
|
{
|
||||||
_body = pBody;
|
_body = pBody;
|
||||||
|
|
||||||
for(auto object : *_colliderBodyList)
|
for(auto& object : _colliderBodyList)
|
||||||
{
|
{
|
||||||
ColliderBody *colliderBody = (ColliderBody *)object;
|
ColliderBody *colliderBody = (ColliderBody *)object;
|
||||||
|
|
||||||
ContourData *contourData = colliderBody->getContourData();
|
ContourData *contourData = colliderBody->getContourData();
|
||||||
const Array *array = &contourData->vertexList;
|
|
||||||
Object *object = nullptr;
|
|
||||||
|
|
||||||
b2Vec2 *b2bv = new b2Vec2[contourData->vertexList.size()];
|
b2Vec2 *b2bv = new b2Vec2[contourData->vertexList.size()];
|
||||||
|
|
||||||
int i = 0;
|
int i = 0;
|
||||||
for(auto object : *array)
|
for(auto& v : contourData->vertexList)
|
||||||
{
|
{
|
||||||
ContourVertex2 *v = (ContourVertex2 *)object;
|
b2bv[i].Set(v.x / PT_RATIO, v.y / PT_RATIO);
|
||||||
b2bv[i].Set(v->x / PT_RATIO, v->y / PT_RATIO);
|
|
||||||
i++;
|
i++;
|
||||||
}
|
}
|
||||||
|
|
||||||
b2PolygonShape polygon;
|
b2PolygonShape polygon;
|
||||||
polygon.Set(b2bv, contourData->vertexList.size());
|
polygon.Set(b2bv, (int)contourData->vertexList.size());
|
||||||
|
|
||||||
CC_SAFE_DELETE(b2bv);
|
CC_SAFE_DELETE(b2bv);
|
||||||
|
|
||||||
|
@ -452,22 +462,22 @@ void ColliderDetector::setBody(cpBody *pBody)
|
||||||
{
|
{
|
||||||
_body = pBody;
|
_body = pBody;
|
||||||
|
|
||||||
for(auto object : *_colliderBodyList)
|
for(auto& object : _colliderBodyList)
|
||||||
{
|
{
|
||||||
ColliderBody *colliderBody = (ColliderBody *)object;
|
ColliderBody *colliderBody = (ColliderBody *)object;
|
||||||
|
|
||||||
ContourData *contourData = colliderBody->getContourData();
|
ContourData *contourData = colliderBody->getContourData();
|
||||||
|
|
||||||
int num = contourData->vertexList.count();
|
ssize_t num = contourData->vertexList.size();
|
||||||
ContourVertex2 **vs = (ContourVertex2 **)contourData->vertexList.data->arr;
|
auto vs = contourData->vertexList;
|
||||||
cpVect *verts = new cpVect[num];
|
cpVect *verts = new cpVect[num];
|
||||||
for (int i = 0; i < num; i++)
|
for (int i = 0; i < num; i++)
|
||||||
{
|
{
|
||||||
verts[num - 1 - i].x = vs[i]->x;
|
verts[num - 1 - i].x = vs.at(i).x;
|
||||||
verts[num - 1 - i].y = vs[i]->y;
|
verts[num - 1 - i].y = vs.at(i).y;
|
||||||
}
|
}
|
||||||
|
|
||||||
cpShape *shape = cpPolyShapeNew(_body, num, verts, cpvzero);
|
cpShape *shape = cpPolyShapeNew(_body, (int)num, verts, cpvzero);
|
||||||
|
|
||||||
shape->sensor = true;
|
shape->sensor = true;
|
||||||
shape->data = _bone;
|
shape->data = _bone;
|
||||||
|
|
|
@ -34,14 +34,12 @@ THE SOFTWARE.
|
||||||
|
|
||||||
|
|
||||||
#if ENABLE_PHYSICS_CHIPMUNK_DETECT
|
#if ENABLE_PHYSICS_CHIPMUNK_DETECT
|
||||||
struct cpBody;
|
#include "chipmunk.h"
|
||||||
struct cpShape;
|
|
||||||
#elif ENABLE_PHYSICS_BOX2D_DETECT
|
#elif ENABLE_PHYSICS_BOX2D_DETECT
|
||||||
class b2Body;
|
#include "Box2D/Box2D.h"
|
||||||
class b2Fixture;
|
|
||||||
struct b2Filter;
|
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
|
||||||
namespace cocostudio {
|
namespace cocostudio {
|
||||||
|
|
||||||
class Bone;
|
class Bone;
|
||||||
|
@ -56,34 +54,34 @@ public:
|
||||||
virtual ~ColliderFilter() { }
|
virtual ~ColliderFilter() { }
|
||||||
#if ENABLE_PHYSICS_BOX2D_DETECT
|
#if ENABLE_PHYSICS_BOX2D_DETECT
|
||||||
public:
|
public:
|
||||||
ColliderFilter(unsigned short categoryBits = 0x0001, unsigned short maskBits = 0xFFFF, signed short groupIndex = 0);
|
ColliderFilter(uint16 categoryBits = 0x0001, uint16 maskBits = 0xFFFF, int16 groupIndex = 0);
|
||||||
void updateShape(b2Fixture *fixture);
|
void updateShape(b2Fixture *fixture);
|
||||||
|
|
||||||
virtual void setCategoryBits(unsigned short categoryBits) { _categoryBits = categoryBits; }
|
virtual void setCategoryBits(uint16 categoryBits) { _categoryBits = categoryBits; }
|
||||||
virtual unsigned short getCategoryBits() const { return _categoryBits; }
|
virtual uint16 getCategoryBits() const { return _categoryBits; }
|
||||||
|
|
||||||
virtual void setMaskBits(unsigned short maskBits) { _maskBits = maskBits; }
|
virtual void setMaskBits(uint16 maskBits) { _maskBits = maskBits; }
|
||||||
virtual unsigned short getMaskBits() const { return _maskBits; }
|
virtual uint16 getMaskBits() const { return _maskBits; }
|
||||||
|
|
||||||
virtual void setGroupIndex(signed short groupIndex) { _groupIndex = groupIndex; }
|
virtual void setGroupIndex(int16 groupIndex) { _groupIndex = groupIndex; }
|
||||||
virtual signed short getGroupIndex() const { return _groupIndex; }
|
virtual int16 getGroupIndex() const { return _groupIndex; }
|
||||||
protected:
|
protected:
|
||||||
unsigned short _categoryBits;
|
uint16 _categoryBits;
|
||||||
unsigned short _maskBits;
|
uint16 _maskBits;
|
||||||
signed short _groupIndex;
|
int16 _groupIndex;
|
||||||
#elif ENABLE_PHYSICS_CHIPMUNK_DETECT
|
#elif ENABLE_PHYSICS_CHIPMUNK_DETECT
|
||||||
public:
|
public:
|
||||||
ColliderFilter(uintptr_t collisionType = 0, uintptr_t group = 0);
|
ColliderFilter(cpCollisionType collisionType = 0, cpGroup group = 0);
|
||||||
void updateShape(cpShape *shape);
|
void updateShape(cpShape *shape);
|
||||||
|
|
||||||
virtual void setCollisionType(uintptr_t collisionType) { _collisionType = collisionType; }
|
virtual void setCollisionType(cpCollisionType collisionType) { _collisionType = collisionType; }
|
||||||
virtual uintptr_t getCollisionType() const { return _collisionType; }
|
virtual cpCollisionType getCollisionType() const { return _collisionType; }
|
||||||
|
|
||||||
virtual void setGroup(uintptr_t group) { _group = group; }
|
virtual void setGroup(cpGroup group) { _group = group; }
|
||||||
virtual uintptr_t getGroup() const { return _group; }
|
virtual cpGroup getGroup() const { return _group; }
|
||||||
protected:
|
protected:
|
||||||
uintptr_t _collisionType;
|
cpCollisionType _collisionType;
|
||||||
uintptr_t _group;
|
cpGroup _group;
|
||||||
#endif
|
#endif
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -95,8 +93,10 @@ public:
|
||||||
|
|
||||||
inline ContourData *getContourData() { return _contourData; }
|
inline ContourData *getContourData() { return _contourData; }
|
||||||
|
|
||||||
|
#if ENABLE_PHYSICS_BOX2D_DETECT || ENABLE_PHYSICS_CHIPMUNK_DETECT
|
||||||
void setColliderFilter(ColliderFilter *filter);
|
void setColliderFilter(ColliderFilter *filter);
|
||||||
ColliderFilter *getColliderFilter();
|
ColliderFilter *getColliderFilter();
|
||||||
|
#endif
|
||||||
|
|
||||||
#if ENABLE_PHYSICS_BOX2D_DETECT
|
#if ENABLE_PHYSICS_BOX2D_DETECT
|
||||||
virtual void setB2Fixture(b2Fixture *fixture) { _fixture = fixture; }
|
virtual void setB2Fixture(b2Fixture *fixture) { _fixture = fixture; }
|
||||||
|
@ -104,25 +104,25 @@ public:
|
||||||
#elif ENABLE_PHYSICS_CHIPMUNK_DETECT
|
#elif ENABLE_PHYSICS_CHIPMUNK_DETECT
|
||||||
virtual void setShape(cpShape *shape) { _shape = shape; }
|
virtual void setShape(cpShape *shape) { _shape = shape; }
|
||||||
virtual cpShape *getShape() const { return _shape; }
|
virtual cpShape *getShape() const { return _shape; }
|
||||||
|
#elif ENABLE_PHYSICS_SAVE_CALCULATED_VERTEX
|
||||||
|
virtual const std::vector<cocos2d::Point> &getCalculatedVertexList() const { return _calculatedVertexList; }
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#if ENABLE_PHYSICS_SAVE_CALCULATED_VERTEX
|
|
||||||
virtual const cocos2d::Array *getCalculatedVertexList() const { return _calculatedVertexList; }
|
|
||||||
#endif
|
|
||||||
private:
|
private:
|
||||||
|
|
||||||
#if ENABLE_PHYSICS_BOX2D_DETECT
|
#if ENABLE_PHYSICS_BOX2D_DETECT
|
||||||
b2Fixture *_fixture;
|
b2Fixture *_fixture;
|
||||||
|
ColliderFilter *_filter;
|
||||||
#elif ENABLE_PHYSICS_CHIPMUNK_DETECT
|
#elif ENABLE_PHYSICS_CHIPMUNK_DETECT
|
||||||
cpShape *_shape;
|
cpShape *_shape;
|
||||||
|
ColliderFilter *_filter;
|
||||||
|
#elif ENABLE_PHYSICS_SAVE_CALCULATED_VERTEX
|
||||||
|
std::vector<cocos2d::Point> _calculatedVertexList;
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
ContourData *_contourData;
|
ContourData *_contourData;
|
||||||
ColliderFilter *_filter;
|
|
||||||
|
|
||||||
#if ENABLE_PHYSICS_SAVE_CALCULATED_VERTEX
|
friend class ColliderDetector;
|
||||||
cocos2d::Array *_calculatedVertexList;
|
|
||||||
#endif
|
|
||||||
};
|
};
|
||||||
|
|
||||||
/*
|
/*
|
||||||
|
@ -150,7 +150,7 @@ public:
|
||||||
virtual bool init(Bone *bone);
|
virtual bool init(Bone *bone);
|
||||||
|
|
||||||
void addContourData(ContourData *contourData);
|
void addContourData(ContourData *contourData);
|
||||||
void addContourDataList(cocos2d::Array *contourDataList);
|
void addContourDataList(cocos2d::Vector<ContourData*> &contourDataList);
|
||||||
|
|
||||||
void removeContourData(ContourData *contourData);
|
void removeContourData(ContourData *contourData);
|
||||||
void removeAll();
|
void removeAll();
|
||||||
|
@ -160,10 +160,12 @@ public:
|
||||||
void setActive(bool active);
|
void setActive(bool active);
|
||||||
bool getActive();
|
bool getActive();
|
||||||
|
|
||||||
cocos2d::Array *getColliderBodyList();
|
const cocos2d::Vector<ColliderBody*>& getColliderBodyList();
|
||||||
|
|
||||||
|
#if ENABLE_PHYSICS_BOX2D_DETECT || ENABLE_PHYSICS_CHIPMUNK_DETECT
|
||||||
virtual void setColliderFilter(ColliderFilter *filter);
|
virtual void setColliderFilter(ColliderFilter *filter);
|
||||||
virtual ColliderFilter *getColliderFilter();
|
virtual ColliderFilter *getColliderFilter();
|
||||||
|
#endif
|
||||||
|
|
||||||
virtual void setBone(Bone *bone) { _bone = bone; }
|
virtual void setBone(Bone *bone) { _bone = bone; }
|
||||||
virtual Bone *getBone() const { return _bone; }
|
virtual Bone *getBone() const { return _bone; }
|
||||||
|
@ -176,15 +178,16 @@ public:
|
||||||
virtual cpBody *getBody() const;
|
virtual cpBody *getBody() const;
|
||||||
#endif
|
#endif
|
||||||
protected:
|
protected:
|
||||||
cocos2d::Array *_colliderBodyList;
|
cocos2d::Vector<ColliderBody*> _colliderBodyList;
|
||||||
ColliderFilter *_filter;
|
|
||||||
|
|
||||||
Bone *_bone;
|
Bone *_bone;
|
||||||
|
|
||||||
#if ENABLE_PHYSICS_BOX2D_DETECT
|
#if ENABLE_PHYSICS_BOX2D_DETECT
|
||||||
b2Body *_body;
|
b2Body *_body;
|
||||||
|
ColliderFilter *_filter;
|
||||||
#elif ENABLE_PHYSICS_CHIPMUNK_DETECT
|
#elif ENABLE_PHYSICS_CHIPMUNK_DETECT
|
||||||
cpBody *_body;
|
cpBody *_body;
|
||||||
|
ColliderFilter *_filter;
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
|
|
|
@ -73,6 +73,8 @@ static const char *A_EVENT = "evt";
|
||||||
static const char *A_SOUND = "sd";
|
static const char *A_SOUND = "sd";
|
||||||
static const char *A_SOUND_EFFECT = "sdE";
|
static const char *A_SOUND_EFFECT = "sdE";
|
||||||
static const char *A_TWEEN_EASING = "twE";
|
static const char *A_TWEEN_EASING = "twE";
|
||||||
|
//static const char *A_EASING_PARAM_NUMBER = "twEPN";
|
||||||
|
static const char *A_EASING_PARAM = "twEP";
|
||||||
//static const char *A_TWEEN_ROTATE = "twR";
|
//static const char *A_TWEEN_ROTATE = "twR";
|
||||||
static const char *A_IS_ARMATURE = "isArmature";
|
static const char *A_IS_ARMATURE = "isArmature";
|
||||||
static const char *A_DISPLAY_TYPE = "displayType";
|
static const char *A_DISPLAY_TYPE = "displayType";
|
||||||
|
@ -93,6 +95,8 @@ static const char *A_COCOS2D_PIVOT_X = "cocos2d_pX";
|
||||||
static const char *A_COCOS2D_PIVOT_Y = "cocos2d_pY";
|
static const char *A_COCOS2D_PIVOT_Y = "cocos2d_pY";
|
||||||
|
|
||||||
static const char *A_BLEND_TYPE = "bd";
|
static const char *A_BLEND_TYPE = "bd";
|
||||||
|
static const char *A_BLEND_SRC = "bd_src";
|
||||||
|
static const char *A_BLEND_DST = "bd_dst";
|
||||||
|
|
||||||
static const char *A_ALPHA = "a";
|
static const char *A_ALPHA = "a";
|
||||||
static const char *A_RED = "r";
|
static const char *A_RED = "r";
|
||||||
|
@ -820,8 +824,8 @@ MovementBoneData *DataReaderHelper::decodeMovementBone(tinyxml2::XMLElement *mov
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
int length = 0;
|
unsigned long length = 0;
|
||||||
int index = 0;
|
unsigned long index = 0;
|
||||||
int parentTotalDuration = 0;
|
int parentTotalDuration = 0;
|
||||||
int currentDuration = 0;
|
int currentDuration = 0;
|
||||||
|
|
||||||
|
@ -884,22 +888,22 @@ MovementBoneData *DataReaderHelper::decodeMovementBone(tinyxml2::XMLElement *mov
|
||||||
|
|
||||||
|
|
||||||
//! Change rotation range from (-180 -- 180) to (-infinity -- infinity)
|
//! Change rotation range from (-180 -- 180) to (-infinity -- infinity)
|
||||||
FrameData **frames = (FrameData **)movBoneData->frameList.data->arr;
|
auto frames = movBoneData->frameList;
|
||||||
for (int j = movBoneData->frameList.count() - 1; j >= 0; j--)
|
for (long j = movBoneData->frameList.size() - 1; j >= 0; j--)
|
||||||
{
|
{
|
||||||
if (j > 0)
|
if (j > 0)
|
||||||
{
|
{
|
||||||
float difSkewX = frames[j]->skewX - frames[j - 1]->skewX;
|
float difSkewX = frames.at(j)->skewX - frames.at(j-1)->skewX;
|
||||||
float difSkewY = frames[j]->skewY - frames[j - 1]->skewY;
|
float difSkewY = frames.at(j)->skewY - frames.at(j-1)->skewY;
|
||||||
|
|
||||||
if (difSkewX < -M_PI || difSkewX > M_PI)
|
if (difSkewX < -M_PI || difSkewX > M_PI)
|
||||||
{
|
{
|
||||||
frames[j - 1]->skewX = difSkewX < 0 ? frames[j - 1]->skewX - 2 * M_PI : frames[j - 1]->skewX + 2 * M_PI;
|
frames.at(j-1)->skewX = difSkewX < 0 ? frames.at(j-1)->skewX - 2 * M_PI : frames.at(j-1)->skewX + 2 * M_PI;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (difSkewY < -M_PI || difSkewY > M_PI)
|
if (difSkewY < -M_PI || difSkewY > M_PI)
|
||||||
{
|
{
|
||||||
frames[j - 1]->skewY = difSkewY < 0 ? frames[j - 1]->skewY - 2 * M_PI : frames[j - 1]->skewY + 2 * M_PI;
|
frames.at(j-1)->skewY = difSkewY < 0 ? frames.at(j-1)->skewY - 2 * M_PI : frames.at(j-1)->skewY + 2 * M_PI;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -907,7 +911,7 @@ MovementBoneData *DataReaderHelper::decodeMovementBone(tinyxml2::XMLElement *mov
|
||||||
|
|
||||||
//
|
//
|
||||||
FrameData *frameData = new FrameData();
|
FrameData *frameData = new FrameData();
|
||||||
frameData->copy((FrameData *)movBoneData->frameList.getLastObject());
|
frameData->copy((FrameData *)movBoneData->frameList.back());
|
||||||
frameData->frameID = movBoneData->duration;
|
frameData->frameID = movBoneData->duration;
|
||||||
movBoneData->addFrameData(frameData);
|
movBoneData->addFrameData(frameData);
|
||||||
frameData->release();
|
frameData->release();
|
||||||
|
@ -939,6 +943,11 @@ FrameData *DataReaderHelper::decodeFrame(tinyxml2::XMLElement *frameXML, tinyxm
|
||||||
frameData->strSoundEffect = frameXML->Attribute(A_SOUND_EFFECT);
|
frameData->strSoundEffect = frameXML->Attribute(A_SOUND_EFFECT);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bool tweenFrame = false;
|
||||||
|
if (frameXML->QueryBoolAttribute(A_TWEEN_FRAME, &tweenFrame) == tinyxml2::XML_SUCCESS)
|
||||||
|
{
|
||||||
|
frameData->isTween = tweenFrame;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
if (dataInfo->flashToolVersion >= VERSION_2_0)
|
if (dataInfo->flashToolVersion >= VERSION_2_0)
|
||||||
|
@ -998,7 +1007,38 @@ FrameData *DataReaderHelper::decodeFrame(tinyxml2::XMLElement *frameXML, tinyxm
|
||||||
}
|
}
|
||||||
if ( frameXML->QueryIntAttribute(A_BLEND_TYPE, &blendType) == tinyxml2::XML_SUCCESS )
|
if ( frameXML->QueryIntAttribute(A_BLEND_TYPE, &blendType) == tinyxml2::XML_SUCCESS )
|
||||||
{
|
{
|
||||||
frameData->blendType = (BlendType)blendType;
|
switch (blendType)
|
||||||
|
{
|
||||||
|
case BLEND_NORMAL:
|
||||||
|
{
|
||||||
|
frameData->blendFunc = BlendFunc::ALPHA_NON_PREMULTIPLIED;
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
case BLEND_ADD:
|
||||||
|
{
|
||||||
|
frameData->blendFunc.src = GL_SRC_ALPHA;
|
||||||
|
frameData->blendFunc.dst = GL_ONE;
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
case BLEND_MULTIPLY:
|
||||||
|
{
|
||||||
|
frameData->blendFunc.src = GL_DST_COLOR;
|
||||||
|
frameData->blendFunc.dst = GL_ONE_MINUS_SRC_ALPHA;
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
case BLEND_SCREEN:
|
||||||
|
{
|
||||||
|
frameData->blendFunc.src = GL_ONE;
|
||||||
|
frameData->blendFunc.dst = GL_ONE_MINUS_SRC_COLOR;
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
{
|
||||||
|
frameData->blendFunc.src = CC_BLEND_SRC;
|
||||||
|
frameData->blendFunc.dst = CC_BLEND_DST;
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
tinyxml2::XMLElement *colorTransformXML = frameXML->FirstChildElement(A_COLOR_TRANSFORM);
|
tinyxml2::XMLElement *colorTransformXML = frameXML->FirstChildElement(A_COLOR_TRANSFORM);
|
||||||
|
@ -1128,14 +1168,13 @@ ContourData *DataReaderHelper::decodeContour(tinyxml2::XMLElement *contourXML, D
|
||||||
|
|
||||||
while (vertexDataXML)
|
while (vertexDataXML)
|
||||||
{
|
{
|
||||||
ContourVertex2 *vertex = new ContourVertex2(0, 0);
|
Point vertex;
|
||||||
vertex->release();
|
|
||||||
|
|
||||||
vertexDataXML->QueryFloatAttribute(A_X, &vertex->x);
|
vertexDataXML->QueryFloatAttribute(A_X, &vertex.x);
|
||||||
vertexDataXML->QueryFloatAttribute(A_Y, &vertex->y);
|
vertexDataXML->QueryFloatAttribute(A_Y, &vertex.y);
|
||||||
|
|
||||||
vertex->y = -vertex->y;
|
vertex.y = -vertex.y;
|
||||||
contourData->vertexList.addObject(vertex);
|
contourData->vertexList.push_back(vertex);
|
||||||
|
|
||||||
vertexDataXML = vertexDataXML->NextSiblingElement(CONTOUR_VERTEX);
|
vertexDataXML = vertexDataXML->NextSiblingElement(CONTOUR_VERTEX);
|
||||||
}
|
}
|
||||||
|
@ -1362,11 +1401,11 @@ DisplayData *DataReaderHelper::decodeBoneDisplay(JsonDictionary &json, DataInfo
|
||||||
{
|
{
|
||||||
if (dataInfo->asyncStruct)
|
if (dataInfo->asyncStruct)
|
||||||
{
|
{
|
||||||
static_cast<ParticleDisplayData *>(displayData)->plist = dataInfo->asyncStruct->baseFilePath + plist;
|
static_cast<ParticleDisplayData *>(displayData)->displayName = dataInfo->asyncStruct->baseFilePath + plist;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
static_cast<ParticleDisplayData *>(displayData)->plist = dataInfo->baseFilePath + plist;
|
static_cast<ParticleDisplayData *>(displayData)->displayName = dataInfo->baseFilePath + plist;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1474,22 +1513,22 @@ MovementBoneData *DataReaderHelper::decodeMovementBone(JsonDictionary &json, Dat
|
||||||
if (dataInfo->cocoStudioVersion < VERSION_CHANGE_ROTATION_RANGE)
|
if (dataInfo->cocoStudioVersion < VERSION_CHANGE_ROTATION_RANGE)
|
||||||
{
|
{
|
||||||
//! Change rotation range from (-180 -- 180) to (-infinity -- infinity)
|
//! Change rotation range from (-180 -- 180) to (-infinity -- infinity)
|
||||||
FrameData **frames = (FrameData **)movementBoneData->frameList.data->arr;
|
auto frames = movementBoneData->frameList;
|
||||||
for (int i = movementBoneData->frameList.count() - 1; i >= 0; i--)
|
for (long i = frames.size() - 1; i >= 0; i--)
|
||||||
{
|
{
|
||||||
if (i > 0)
|
if (i > 0)
|
||||||
{
|
{
|
||||||
float difSkewX = frames[i]->skewX - frames[i - 1]->skewX;
|
float difSkewX = frames.at(i)->skewX - frames.at(i-1)->skewX;
|
||||||
float difSkewY = frames[i]->skewY - frames[i - 1]->skewY;
|
float difSkewY = frames.at(i)->skewY - frames.at(i-1)->skewY;
|
||||||
|
|
||||||
if (difSkewX < -M_PI || difSkewX > M_PI)
|
if (difSkewX < -M_PI || difSkewX > M_PI)
|
||||||
{
|
{
|
||||||
frames[i - 1]->skewX = difSkewX < 0 ? frames[i - 1]->skewX - 2 * M_PI : frames[i - 1]->skewX + 2 * M_PI;
|
frames.at(i-1)->skewX = difSkewX < 0 ? frames.at(i-1)->skewX - 2 * M_PI : frames.at(i-1)->skewX + 2 * M_PI;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (difSkewY < -M_PI || difSkewY > M_PI)
|
if (difSkewY < -M_PI || difSkewY > M_PI)
|
||||||
{
|
{
|
||||||
frames[i - 1]->skewY = difSkewY < 0 ? frames[i - 1]->skewY - 2 * M_PI : frames[i - 1]->skewY + 2 * M_PI;
|
frames.at(i-1)->skewY = difSkewY < 0 ? frames.at(i-1)->skewY - 2 * M_PI : frames.at(i-1)->skewY + 2 * M_PI;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1497,10 +1536,10 @@ MovementBoneData *DataReaderHelper::decodeMovementBone(JsonDictionary &json, Dat
|
||||||
|
|
||||||
if (dataInfo->cocoStudioVersion < VERSION_COMBINED)
|
if (dataInfo->cocoStudioVersion < VERSION_COMBINED)
|
||||||
{
|
{
|
||||||
if (movementBoneData->frameList.count() > 0)
|
if (movementBoneData->frameList.size() > 0)
|
||||||
{
|
{
|
||||||
FrameData *frameData = new FrameData();
|
FrameData *frameData = new FrameData();
|
||||||
frameData->copy((FrameData *)movementBoneData->frameList.getLastObject());
|
frameData->copy((FrameData *)movementBoneData->frameList.back());
|
||||||
movementBoneData->addFrameData(frameData);
|
movementBoneData->addFrameData(frameData);
|
||||||
frameData->release();
|
frameData->release();
|
||||||
|
|
||||||
|
@ -1519,7 +1558,8 @@ FrameData *DataReaderHelper::decodeFrame(JsonDictionary &json, DataInfo *dataInf
|
||||||
|
|
||||||
frameData->tweenEasing = (TweenType)json.getItemIntValue(A_TWEEN_EASING, Linear);
|
frameData->tweenEasing = (TweenType)json.getItemIntValue(A_TWEEN_EASING, Linear);
|
||||||
frameData->displayIndex = json.getItemIntValue(A_DISPLAY_INDEX, 0);
|
frameData->displayIndex = json.getItemIntValue(A_DISPLAY_INDEX, 0);
|
||||||
frameData->blendType = (BlendType)json.getItemIntValue(A_BLEND_TYPE, 0);
|
frameData->blendFunc.src = (GLenum)(json.getItemIntValue(A_BLEND_SRC, BlendFunc::ALPHA_NON_PREMULTIPLIED.src));
|
||||||
|
frameData->blendFunc.dst = (GLenum)(json.getItemIntValue(A_BLEND_DST, BlendFunc::ALPHA_NON_PREMULTIPLIED.dst));
|
||||||
frameData->isTween = (bool)json.getItemBoolvalue(A_TWEEN_FRAME, true);
|
frameData->isTween = (bool)json.getItemBoolvalue(A_TWEEN_FRAME, true);
|
||||||
|
|
||||||
const char *event = json.getItemStringValue(A_EVENT);
|
const char *event = json.getItemStringValue(A_EVENT);
|
||||||
|
@ -1537,6 +1577,18 @@ FrameData *DataReaderHelper::decodeFrame(JsonDictionary &json, DataInfo *dataInf
|
||||||
frameData->frameID = json.getItemIntValue(A_FRAME_INDEX, 0);
|
frameData->frameID = json.getItemIntValue(A_FRAME_INDEX, 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
int length = json.getArrayItemCount(A_EASING_PARAM);
|
||||||
|
if (length != 0)
|
||||||
|
{
|
||||||
|
frameData->easingParams = new float[length];
|
||||||
|
|
||||||
|
for (int i = 0; i < length; i++)
|
||||||
|
{
|
||||||
|
frameData->easingParams[i] = json.getFloatValueFromArray(A_EASING_PARAM, i, 0);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
return frameData;
|
return frameData;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1561,7 +1613,7 @@ TextureData *DataReaderHelper::decodeTexture(JsonDictionary &json)
|
||||||
{
|
{
|
||||||
JsonDictionary *dic = json.getSubItemFromArray(CONTOUR_DATA, i);
|
JsonDictionary *dic = json.getSubItemFromArray(CONTOUR_DATA, i);
|
||||||
ContourData *contourData = decodeContour(*dic);
|
ContourData *contourData = decodeContour(*dic);
|
||||||
textureData->contourDataList.addObject(contourData);
|
textureData->contourDataList.pushBack(contourData);
|
||||||
contourData->release();
|
contourData->release();
|
||||||
|
|
||||||
delete dic;
|
delete dic;
|
||||||
|
@ -1580,13 +1632,12 @@ ContourData *DataReaderHelper::decodeContour(JsonDictionary &json)
|
||||||
{
|
{
|
||||||
JsonDictionary *dic = json.getSubItemFromArray(VERTEX_POINT, i);
|
JsonDictionary *dic = json.getSubItemFromArray(VERTEX_POINT, i);
|
||||||
|
|
||||||
ContourVertex2 *vertex = new ContourVertex2(0, 0);
|
Point vertex;
|
||||||
|
|
||||||
vertex->x = dic->getItemFloatValue(A_X, 0);
|
vertex.x = dic->getItemFloatValue(A_X, 0);
|
||||||
vertex->y = dic->getItemFloatValue(A_Y, 0);
|
vertex.y = dic->getItemFloatValue(A_Y, 0);
|
||||||
|
|
||||||
contourData->vertexList.addObject(vertex);
|
contourData->vertexList.push_back(vertex);
|
||||||
vertex->release();
|
|
||||||
|
|
||||||
delete dic;
|
delete dic;
|
||||||
}
|
}
|
||||||
|
|
|
@ -158,58 +158,42 @@ const char *DisplayData::changeDisplayToTexture(const char *displayName)
|
||||||
|
|
||||||
DisplayData::DisplayData(void)
|
DisplayData::DisplayData(void)
|
||||||
: displayType(CS_DISPLAY_MAX)
|
: displayType(CS_DISPLAY_MAX)
|
||||||
|
, displayName("")
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
DisplayData::~DisplayData(void)
|
void DisplayData::copy(DisplayData *displayData)
|
||||||
{
|
{
|
||||||
|
displayName = displayData->displayName;
|
||||||
|
displayType = displayData->displayType;
|
||||||
}
|
}
|
||||||
|
|
||||||
SpriteDisplayData::SpriteDisplayData(void)
|
SpriteDisplayData::SpriteDisplayData(void)
|
||||||
: displayName("")
|
|
||||||
{
|
{
|
||||||
displayType = CS_DISPLAY_SPRITE;
|
displayType = CS_DISPLAY_SPRITE;
|
||||||
}
|
}
|
||||||
|
|
||||||
SpriteDisplayData::~SpriteDisplayData()
|
|
||||||
{
|
|
||||||
}
|
|
||||||
|
|
||||||
void SpriteDisplayData::copy(SpriteDisplayData *displayData)
|
void SpriteDisplayData::copy(DisplayData *displayData)
|
||||||
{
|
{
|
||||||
displayName = displayData->displayName;
|
DisplayData::copy(displayData);
|
||||||
displayType = displayData->displayType;
|
|
||||||
|
|
||||||
skinData = displayData->skinData;
|
if (SpriteDisplayData *sdd = dynamic_cast<SpriteDisplayData*>(displayData))
|
||||||
|
{
|
||||||
|
skinData = sdd->skinData;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
ArmatureDisplayData::ArmatureDisplayData(void)
|
ArmatureDisplayData::ArmatureDisplayData(void)
|
||||||
: displayName("")
|
|
||||||
{
|
{
|
||||||
displayType = CS_DISPLAY_ARMATURE;
|
displayType = CS_DISPLAY_ARMATURE;
|
||||||
}
|
}
|
||||||
|
|
||||||
ArmatureDisplayData::~ArmatureDisplayData()
|
|
||||||
{
|
|
||||||
}
|
|
||||||
|
|
||||||
void ArmatureDisplayData::copy(ArmatureDisplayData *displayData)
|
|
||||||
{
|
|
||||||
displayName = displayData->displayName;
|
|
||||||
displayType = displayData->displayType;
|
|
||||||
}
|
|
||||||
|
|
||||||
ParticleDisplayData::ParticleDisplayData(void)
|
ParticleDisplayData::ParticleDisplayData(void)
|
||||||
: plist("")
|
|
||||||
{
|
{
|
||||||
displayType = CS_DISPLAY_PARTICLE;
|
displayType = CS_DISPLAY_PARTICLE;
|
||||||
}
|
}
|
||||||
|
|
||||||
void ParticleDisplayData::copy(ParticleDisplayData *displayData)
|
|
||||||
{
|
|
||||||
plist = displayData->plist;
|
|
||||||
displayType = displayData->displayType;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
BoneData::BoneData(void)
|
BoneData::BoneData(void)
|
||||||
|
@ -224,18 +208,17 @@ BoneData::~BoneData(void)
|
||||||
|
|
||||||
bool BoneData::init()
|
bool BoneData::init()
|
||||||
{
|
{
|
||||||
displayDataList.init();
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
void BoneData::addDisplayData(DisplayData *displayData)
|
void BoneData::addDisplayData(DisplayData *displayData)
|
||||||
{
|
{
|
||||||
displayDataList.addObject(displayData);
|
displayDataList.pushBack(displayData);
|
||||||
}
|
}
|
||||||
|
|
||||||
DisplayData *BoneData::getDisplayData(int index)
|
DisplayData *BoneData::getDisplayData(int index)
|
||||||
{
|
{
|
||||||
return static_cast<DisplayData *>(displayDataList.getObjectAtIndex(index));
|
return displayDataList.at(index);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -255,21 +238,23 @@ bool ArmatureData::init()
|
||||||
|
|
||||||
void ArmatureData::addBoneData(BoneData *boneData)
|
void ArmatureData::addBoneData(BoneData *boneData)
|
||||||
{
|
{
|
||||||
boneDataDic.setObject(boneData, boneData->name);
|
boneDataDic.insert(boneData->name, boneData);
|
||||||
}
|
}
|
||||||
|
|
||||||
BoneData *ArmatureData::getBoneData(const char *boneName)
|
BoneData *ArmatureData::getBoneData(const char *boneName)
|
||||||
{
|
{
|
||||||
return static_cast<BoneData*>(boneDataDic.objectForKey(boneName));
|
return static_cast<BoneData*>(boneDataDic.at(boneName));
|
||||||
}
|
}
|
||||||
|
|
||||||
FrameData::FrameData(void)
|
FrameData::FrameData(void)
|
||||||
: frameID(0)
|
: frameID(0)
|
||||||
, duration(1)
|
, duration(1)
|
||||||
, tweenEasing(Linear)
|
, tweenEasing(Linear)
|
||||||
|
, easingParamNumber(0)
|
||||||
|
, easingParams(NULL)
|
||||||
, isTween(true)
|
, isTween(true)
|
||||||
, displayIndex(0)
|
, displayIndex(0)
|
||||||
, blendType(BLEND_NORMAL)
|
, blendFunc(BlendFunc::ALPHA_NON_PREMULTIPLIED)
|
||||||
|
|
||||||
, strEvent("")
|
, strEvent("")
|
||||||
, strMovement("")
|
, strMovement("")
|
||||||
|
@ -280,6 +265,7 @@ FrameData::FrameData(void)
|
||||||
|
|
||||||
FrameData::~FrameData(void)
|
FrameData::~FrameData(void)
|
||||||
{
|
{
|
||||||
|
CC_SAFE_DELETE(easingParams);
|
||||||
}
|
}
|
||||||
|
|
||||||
void FrameData::copy(const BaseData *baseData)
|
void FrameData::copy(const BaseData *baseData)
|
||||||
|
@ -290,8 +276,21 @@ void FrameData::copy(const BaseData *baseData)
|
||||||
{
|
{
|
||||||
duration = frameData->duration;
|
duration = frameData->duration;
|
||||||
displayIndex = frameData->displayIndex;
|
displayIndex = frameData->displayIndex;
|
||||||
|
|
||||||
tweenEasing = frameData->tweenEasing;
|
tweenEasing = frameData->tweenEasing;
|
||||||
blendType = frameData->blendType;
|
easingParamNumber = frameData->easingParamNumber;
|
||||||
|
|
||||||
|
CC_SAFE_DELETE(easingParams);
|
||||||
|
if (easingParamNumber != 0)
|
||||||
|
{
|
||||||
|
easingParams = new float[easingParamNumber];
|
||||||
|
for (int i = 0; i<easingParamNumber; i++)
|
||||||
|
{
|
||||||
|
easingParams[i] = frameData->easingParams[i];
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
blendFunc = frameData->blendFunc;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -309,17 +308,17 @@ MovementBoneData::~MovementBoneData(void)
|
||||||
|
|
||||||
bool MovementBoneData::init()
|
bool MovementBoneData::init()
|
||||||
{
|
{
|
||||||
return frameList.init();
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
void MovementBoneData::addFrameData(FrameData *frameData)
|
void MovementBoneData::addFrameData(FrameData *frameData)
|
||||||
{
|
{
|
||||||
frameList.addObject(frameData);
|
frameList.pushBack(frameData);
|
||||||
}
|
}
|
||||||
|
|
||||||
FrameData *MovementBoneData::getFrameData(int index)
|
FrameData *MovementBoneData::getFrameData(int index)
|
||||||
{
|
{
|
||||||
return static_cast<FrameData*>(frameList.getObjectAtIndex(index));
|
return frameList.at(index);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -341,12 +340,12 @@ MovementData::~MovementData(void)
|
||||||
|
|
||||||
void MovementData::addMovementBoneData(MovementBoneData *movBoneData)
|
void MovementData::addMovementBoneData(MovementBoneData *movBoneData)
|
||||||
{
|
{
|
||||||
movBoneDataDic.setObject(movBoneData, movBoneData->name);
|
movBoneDataDic.insert(movBoneData->name, movBoneData);
|
||||||
}
|
}
|
||||||
|
|
||||||
MovementBoneData *MovementData::getMovementBoneData(const char *boneName)
|
MovementBoneData *MovementData::getMovementBoneData(const char *boneName)
|
||||||
{
|
{
|
||||||
return static_cast<MovementBoneData *>(movBoneDataDic.objectForKey(boneName));
|
return movBoneDataDic.at(boneName);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -361,18 +360,18 @@ AnimationData::~AnimationData(void)
|
||||||
|
|
||||||
void AnimationData::addMovement(MovementData *movData)
|
void AnimationData::addMovement(MovementData *movData)
|
||||||
{
|
{
|
||||||
movementDataDic.setObject(movData, movData->name);
|
movementDataDic.insert(movData->name, movData);
|
||||||
movementNames.push_back(movData->name);
|
movementNames.push_back(movData->name);
|
||||||
}
|
}
|
||||||
|
|
||||||
MovementData *AnimationData::getMovement(const char *movementName)
|
MovementData *AnimationData::getMovement(const char *movementName)
|
||||||
{
|
{
|
||||||
return static_cast<MovementData *>(movementDataDic.objectForKey(movementName));
|
return movementDataDic.at(movementName);
|
||||||
}
|
}
|
||||||
|
|
||||||
int AnimationData::getMovementCount()
|
ssize_t AnimationData::getMovementCount()
|
||||||
{
|
{
|
||||||
return movementDataDic.count();
|
return movementDataDic.size();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -387,15 +386,12 @@ ContourData::~ContourData()
|
||||||
|
|
||||||
bool ContourData::init()
|
bool ContourData::init()
|
||||||
{
|
{
|
||||||
return vertexList.init();
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
void ContourData::addVertex(Point *vertex)
|
void ContourData::addVertex(Point &vertex)
|
||||||
{
|
{
|
||||||
ContourVertex2 *vertex2 = new ContourVertex2(vertex->x, vertex->y);
|
vertexList.push_back(vertex);
|
||||||
vertex2->autorelease();
|
|
||||||
|
|
||||||
vertexList.addObject(vertex2);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
TextureData::TextureData()
|
TextureData::TextureData()
|
||||||
|
@ -413,17 +409,17 @@ TextureData::~TextureData()
|
||||||
|
|
||||||
bool TextureData::init()
|
bool TextureData::init()
|
||||||
{
|
{
|
||||||
return contourDataList.init();
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
void TextureData::addContourData(ContourData *contourData)
|
void TextureData::addContourData(ContourData *contourData)
|
||||||
{
|
{
|
||||||
contourDataList.addObject(contourData);
|
contourDataList.pushBack(contourData);
|
||||||
}
|
}
|
||||||
|
|
||||||
ContourData *TextureData::getContourData(int index)
|
ContourData *TextureData::getContourData(int index)
|
||||||
{
|
{
|
||||||
return static_cast<ContourData *>(contourDataList.getObjectAtIndex(index));
|
return contourDataList.at(index);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -146,9 +146,12 @@ public:
|
||||||
* @js NA
|
* @js NA
|
||||||
* @lua NA
|
* @lua NA
|
||||||
*/
|
*/
|
||||||
virtual ~DisplayData(void);
|
virtual ~DisplayData(void) {}
|
||||||
|
|
||||||
|
virtual void copy(DisplayData *displayData);
|
||||||
|
|
||||||
DisplayType displayType; //! mark which type your display is
|
DisplayType displayType; //! mark which type your display is
|
||||||
|
std::string displayName;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
|
@ -169,21 +172,10 @@ public:
|
||||||
* @js NA
|
* @js NA
|
||||||
* @lua NA
|
* @lua NA
|
||||||
*/
|
*/
|
||||||
virtual ~SpriteDisplayData();
|
virtual ~SpriteDisplayData() {};
|
||||||
|
|
||||||
void setParam(const char *pszDisplayName) { this->displayName = pszDisplayName; }
|
void copy(DisplayData *displayData);
|
||||||
|
|
||||||
void copy(SpriteDisplayData *displayData);
|
|
||||||
public:
|
public:
|
||||||
/**
|
|
||||||
* If DisplayType is CS_DISPLAY_SPRITE, then Bone will use this image name to create a Sprite from CCSpriteFrameCache.
|
|
||||||
* It should note that when use this name to create Sprite from CCSpriteFrameCache, you should use _displayName + ".png", because when use Texture Packer to pack single image file, the name have ".png".
|
|
||||||
*
|
|
||||||
* If DisplayType is CS_DISPLAY_ARMATURE, the name is the Armature's name. When Bone init display and type is CS_DISPLAY_ARMATURE,
|
|
||||||
* then Bone will create a Armature.
|
|
||||||
*/
|
|
||||||
std::string displayName;
|
|
||||||
|
|
||||||
BaseData skinData;
|
BaseData skinData;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -204,20 +196,7 @@ public:
|
||||||
* @js NA
|
* @js NA
|
||||||
* @lua NA
|
* @lua NA
|
||||||
*/
|
*/
|
||||||
virtual ~ArmatureDisplayData();
|
virtual ~ArmatureDisplayData() {}
|
||||||
|
|
||||||
void setParam(const char *pszDisplayName) { this->displayName = pszDisplayName; }
|
|
||||||
void copy(ArmatureDisplayData *displayData);
|
|
||||||
public:
|
|
||||||
/**
|
|
||||||
* If DisplayType is CS_DISPLAY_SPRITE, then Bone will use this image name to create a Sprite from CCSpriteFrameCache.
|
|
||||||
* It should note that when use this name to create Sprite from CCSpriteFrameCache, you should use _displayName + ".png", because when use Texture Packer to pack single image file, the name have ".png".
|
|
||||||
*
|
|
||||||
* If DisplayType is CS_DISPLAY_ARMATURE, the name is the Armature's name. When Bone init display and type is CS_DISPLAY_ARMATURE,
|
|
||||||
* then Bone will create a Armature.
|
|
||||||
*/
|
|
||||||
std::string displayName;
|
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -238,12 +217,6 @@ public:
|
||||||
* @lua NA
|
* @lua NA
|
||||||
*/
|
*/
|
||||||
virtual ~ParticleDisplayData() {};
|
virtual ~ParticleDisplayData() {};
|
||||||
|
|
||||||
void setParam(const char *pszPlistName) { this->plist = pszPlistName; }
|
|
||||||
|
|
||||||
void copy(ParticleDisplayData *displayData);
|
|
||||||
public:
|
|
||||||
std::string plist;
|
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
|
@ -277,7 +250,7 @@ public:
|
||||||
public:
|
public:
|
||||||
std::string name; //! the bone's name
|
std::string name; //! the bone's name
|
||||||
std::string parentName; //! the bone parent's name
|
std::string parentName; //! the bone parent's name
|
||||||
cocos2d::Array displayDataList; //! save DisplayData informations for the Bone
|
cocos2d::Vector<DisplayData*> displayDataList; //! save DisplayData informations for the Bone
|
||||||
cocos2d::AffineTransform boneDataTransform;
|
cocos2d::AffineTransform boneDataTransform;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -309,7 +282,7 @@ public:
|
||||||
BoneData *getBoneData(const char *boneName);
|
BoneData *getBoneData(const char *boneName);
|
||||||
public:
|
public:
|
||||||
std::string name;
|
std::string name;
|
||||||
cocos2d::Dictionary boneDataDic;
|
cocos2d::Map<std::string, BoneData*> boneDataDic;
|
||||||
float dataVersion;
|
float dataVersion;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -354,7 +327,11 @@ public:
|
||||||
public:
|
public:
|
||||||
int frameID;
|
int frameID;
|
||||||
int duration; //! The frame will last duration frames
|
int duration; //! The frame will last duration frames
|
||||||
|
|
||||||
TweenType tweenEasing; //! Every frame's tween easing effect
|
TweenType tweenEasing; //! Every frame's tween easing effect
|
||||||
|
int easingParamNumber;
|
||||||
|
float *easingParams;
|
||||||
|
|
||||||
bool isTween; //! Whether it's a tween key frame
|
bool isTween; //! Whether it's a tween key frame
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -363,7 +340,7 @@ public:
|
||||||
*/
|
*/
|
||||||
int displayIndex;
|
int displayIndex;
|
||||||
|
|
||||||
BlendType blendType;
|
cocos2d::BlendFunc blendFunc;
|
||||||
|
|
||||||
std::string strEvent;
|
std::string strEvent;
|
||||||
/**
|
/**
|
||||||
|
@ -403,7 +380,7 @@ public:
|
||||||
float duration; //! this Bone in this movement will last m_iDuration frames
|
float duration; //! this Bone in this movement will last m_iDuration frames
|
||||||
std::string name; //! bone name
|
std::string name; //! bone name
|
||||||
|
|
||||||
cocos2d::Array frameList;
|
cocos2d::Vector<FrameData*> frameList;
|
||||||
};
|
};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -461,7 +438,7 @@ public:
|
||||||
* @key const char *
|
* @key const char *
|
||||||
* @value MovementBoneData *
|
* @value MovementBoneData *
|
||||||
*/
|
*/
|
||||||
cocos2d::Dictionary movBoneDataDic;
|
cocos2d::Map<std::string, MovementBoneData*> movBoneDataDic;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
|
@ -489,25 +466,14 @@ public:
|
||||||
|
|
||||||
void addMovement(MovementData *movData);
|
void addMovement(MovementData *movData);
|
||||||
MovementData *getMovement(const char *movementName);
|
MovementData *getMovement(const char *movementName);
|
||||||
int getMovementCount();
|
ssize_t getMovementCount();
|
||||||
public:
|
public:
|
||||||
std::string name;
|
std::string name;
|
||||||
cocos2d::Dictionary movementDataDic;
|
cocos2d::Map<std::string, MovementData*> movementDataDic;
|
||||||
std::vector<std::string> movementNames;
|
std::vector<std::string> movementNames;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
struct ContourVertex2 : public cocos2d::Object
|
|
||||||
{
|
|
||||||
ContourVertex2(float xx, float yy)
|
|
||||||
{
|
|
||||||
this->x = xx;
|
|
||||||
this->y = yy;
|
|
||||||
}
|
|
||||||
|
|
||||||
float x;
|
|
||||||
float y;
|
|
||||||
};
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* ContourData include a contour vertex information
|
* ContourData include a contour vertex information
|
||||||
|
@ -530,9 +496,9 @@ public:
|
||||||
~ContourData(void);
|
~ContourData(void);
|
||||||
|
|
||||||
virtual bool init();
|
virtual bool init();
|
||||||
virtual void addVertex(cocos2d::Point *vertex);
|
virtual void addVertex(cocos2d::Point &vertex);
|
||||||
public:
|
public:
|
||||||
cocos2d::Array vertexList; //! Save contour vertex info, vertex saved in a Point
|
std::vector<cocos2d::Point> vertexList; //! Save contour vertex info, vertex saved in a Point
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
|
@ -572,7 +538,7 @@ public:
|
||||||
|
|
||||||
std::string name; //! The texture's name
|
std::string name; //! The texture's name
|
||||||
|
|
||||||
cocos2d::Array contourDataList;
|
cocos2d::Vector<ContourData*> contourDataList;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -45,7 +45,7 @@ DecorativeDisplay::DecorativeDisplay()
|
||||||
, _displayData(nullptr)
|
, _displayData(nullptr)
|
||||||
|
|
||||||
{
|
{
|
||||||
#if ENABLE_PHYSICS_BOX2D_DETECT || ENABLE_PHYSICS_CHIPMUNK_DETECT
|
#if ENABLE_PHYSICS_BOX2D_DETECT || ENABLE_PHYSICS_CHIPMUNK_DETECT || ENABLE_PHYSICS_SAVE_CALCULATED_VERTEX
|
||||||
_colliderDetector = nullptr;
|
_colliderDetector = nullptr;
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
@ -56,7 +56,7 @@ DecorativeDisplay::~DecorativeDisplay(void)
|
||||||
CC_SAFE_RELEASE_NULL(_displayData);
|
CC_SAFE_RELEASE_NULL(_displayData);
|
||||||
CC_SAFE_RELEASE_NULL(_display);
|
CC_SAFE_RELEASE_NULL(_display);
|
||||||
|
|
||||||
#if ENABLE_PHYSICS_BOX2D_DETECT || ENABLE_PHYSICS_CHIPMUNK_DETECT
|
#if ENABLE_PHYSICS_BOX2D_DETECT || ENABLE_PHYSICS_CHIPMUNK_DETECT || ENABLE_PHYSICS_SAVE_CALCULATED_VERTEX
|
||||||
CC_SAFE_RELEASE_NULL(_colliderDetector);
|
CC_SAFE_RELEASE_NULL(_colliderDetector);
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
|
@ -30,7 +30,7 @@ THE SOFTWARE.
|
||||||
#include "cocostudio/CCDatas.h"
|
#include "cocostudio/CCDatas.h"
|
||||||
|
|
||||||
|
|
||||||
#if ENABLE_PHYSICS_BOX2D_DETECT || ENABLE_PHYSICS_CHIPMUNK_DETECT
|
#if ENABLE_PHYSICS_BOX2D_DETECT || ENABLE_PHYSICS_CHIPMUNK_DETECT || ENABLE_PHYSICS_SAVE_CALCULATED_VERTEX
|
||||||
#include "cocostudio/CCColliderDetector.h"
|
#include "cocostudio/CCColliderDetector.h"
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
@ -71,7 +71,7 @@ public:
|
||||||
}
|
}
|
||||||
virtual DisplayData *getDisplayData() const { return _displayData; }
|
virtual DisplayData *getDisplayData() const { return _displayData; }
|
||||||
|
|
||||||
#if ENABLE_PHYSICS_BOX2D_DETECT || ENABLE_PHYSICS_CHIPMUNK_DETECT
|
#if ENABLE_PHYSICS_BOX2D_DETECT || ENABLE_PHYSICS_CHIPMUNK_DETECT || ENABLE_PHYSICS_SAVE_CALCULATED_VERTEX
|
||||||
virtual void setColliderDetector(ColliderDetector *detector)
|
virtual void setColliderDetector(ColliderDetector *detector)
|
||||||
{
|
{
|
||||||
if (_colliderDetector != detector)
|
if (_colliderDetector != detector)
|
||||||
|
@ -87,7 +87,7 @@ protected:
|
||||||
cocos2d::Node *_display;
|
cocos2d::Node *_display;
|
||||||
DisplayData *_displayData;
|
DisplayData *_displayData;
|
||||||
|
|
||||||
#if ENABLE_PHYSICS_BOX2D_DETECT || ENABLE_PHYSICS_CHIPMUNK_DETECT
|
#if ENABLE_PHYSICS_BOX2D_DETECT || ENABLE_PHYSICS_CHIPMUNK_DETECT || ENABLE_PHYSICS_SAVE_CALCULATED_VERTEX
|
||||||
ColliderDetector *_colliderDetector;
|
ColliderDetector *_colliderDetector;
|
||||||
#endif
|
#endif
|
||||||
};
|
};
|
||||||
|
|
|
@ -75,30 +75,6 @@ void DisplayFactory::updateDisplay(Bone *bone, float dt, bool dirty)
|
||||||
Node *display = bone->getDisplayRenderNode();
|
Node *display = bone->getDisplayRenderNode();
|
||||||
CS_RETURN_IF(!display);
|
CS_RETURN_IF(!display);
|
||||||
|
|
||||||
#if ENABLE_PHYSICS_BOX2D_DETECT || ENABLE_PHYSICS_CHIPMUNK_DETECT
|
|
||||||
if (dirty)
|
|
||||||
{
|
|
||||||
DecorativeDisplay *decoDisplay = bone->getDisplayManager()->getCurrentDecorativeDisplay();
|
|
||||||
ColliderDetector *detector = decoDisplay->getColliderDetector();
|
|
||||||
if (detector)
|
|
||||||
{
|
|
||||||
do
|
|
||||||
{
|
|
||||||
CC_BREAK_IF(!detector->getBody());
|
|
||||||
|
|
||||||
kmMat4 displayTransform = display->getNodeToParentTransform();
|
|
||||||
Point anchorPoint = display->getAnchorPointInPoints();
|
|
||||||
anchorPoint = PointApplyTransform(anchorPoint, displayTransform);
|
|
||||||
displayTransform.mat[12] = anchorPoint.x;
|
|
||||||
displayTransform.mat[13] = anchorPoint.y;
|
|
||||||
kmMat4 t = TransformConcat(displayTransform, bone->getArmature()->getNodeToParentTransform());
|
|
||||||
detector->updateTransform(t);
|
|
||||||
}
|
|
||||||
while (0);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
#endif
|
|
||||||
|
|
||||||
switch(bone->getDisplayRenderNodeType())
|
switch(bone->getDisplayRenderNodeType())
|
||||||
{
|
{
|
||||||
case CS_DISPLAY_SPRITE:
|
case CS_DISPLAY_SPRITE:
|
||||||
|
@ -119,6 +95,33 @@ void DisplayFactory::updateDisplay(Bone *bone, float dt, bool dirty)
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
#if ENABLE_PHYSICS_BOX2D_DETECT || ENABLE_PHYSICS_CHIPMUNK_DETECT || ENABLE_PHYSICS_SAVE_CALCULATED_VERTEX
|
||||||
|
if (dirty)
|
||||||
|
{
|
||||||
|
DecorativeDisplay *decoDisplay = bone->getDisplayManager()->getCurrentDecorativeDisplay();
|
||||||
|
ColliderDetector *detector = decoDisplay->getColliderDetector();
|
||||||
|
if (detector)
|
||||||
|
{
|
||||||
|
do
|
||||||
|
{
|
||||||
|
#if ENABLE_PHYSICS_BOX2D_DETECT || ENABLE_PHYSICS_CHIPMUNK_DETECT
|
||||||
|
CC_BREAK_IF(!detector->getBody());
|
||||||
|
#endif
|
||||||
|
|
||||||
|
kmMat4 displayTransform = display->getNodeToParentTransform();
|
||||||
|
Point anchorPoint = display->getAnchorPointInPoints();
|
||||||
|
anchorPoint = PointApplyTransform(anchorPoint, displayTransform);
|
||||||
|
displayTransform.mat[12] = anchorPoint.x;
|
||||||
|
displayTransform.mat[13] = anchorPoint.y;
|
||||||
|
kmMat4 t = TransformConcat(displayTransform, bone->getArmature()->getNodeToParentTransform());
|
||||||
|
detector->updateTransform(t);
|
||||||
|
}
|
||||||
|
while (0);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -200,13 +203,13 @@ void DisplayFactory::initSpriteDisplay(Bone *bone, DecorativeDisplay *decoDispla
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
#if ENABLE_PHYSICS_BOX2D_DETECT || ENABLE_PHYSICS_CHIPMUNK_DETECT
|
#if ENABLE_PHYSICS_BOX2D_DETECT || ENABLE_PHYSICS_CHIPMUNK_DETECT || ENABLE_PHYSICS_SAVE_CALCULATED_VERTEX
|
||||||
if (textureData && textureData->contourDataList.count() > 0)
|
if (textureData && textureData->contourDataList.size() > 0)
|
||||||
{
|
{
|
||||||
|
|
||||||
//! create ContourSprite
|
//! create ContourSprite
|
||||||
ColliderDetector *colliderDetector = ColliderDetector::create(bone);
|
ColliderDetector *colliderDetector = ColliderDetector::create(bone);
|
||||||
colliderDetector->addContourDataList(&textureData->contourDataList);
|
colliderDetector->addContourDataList(textureData->contourDataList);
|
||||||
|
|
||||||
decoDisplay->setColliderDetector(colliderDetector);
|
decoDisplay->setColliderDetector(colliderDetector);
|
||||||
}
|
}
|
||||||
|
@ -254,7 +257,7 @@ void DisplayFactory::addParticleDisplay(Bone *bone, DecorativeDisplay *decoDispl
|
||||||
void DisplayFactory::createParticleDisplay(Bone *bone, DecorativeDisplay *decoDisplay)
|
void DisplayFactory::createParticleDisplay(Bone *bone, DecorativeDisplay *decoDisplay)
|
||||||
{
|
{
|
||||||
ParticleDisplayData *displayData = (ParticleDisplayData *)decoDisplay->getDisplayData();
|
ParticleDisplayData *displayData = (ParticleDisplayData *)decoDisplay->getDisplayData();
|
||||||
ParticleSystem *system = ParticleSystemQuad::create(displayData->plist.c_str());
|
ParticleSystem *system = ParticleSystemQuad::create(displayData->displayName.c_str());
|
||||||
|
|
||||||
system->removeFromParent();
|
system->removeFromParent();
|
||||||
|
|
||||||
|
|
|
@ -46,8 +46,7 @@ DisplayManager *DisplayManager::create(Bone *bone)
|
||||||
|
|
||||||
|
|
||||||
DisplayManager::DisplayManager()
|
DisplayManager::DisplayManager()
|
||||||
: _decoDisplayList(nullptr)
|
: _displayRenderNode(nullptr)
|
||||||
, _displayRenderNode(nullptr)
|
|
||||||
, _displayType(CS_DISPLAY_MAX)
|
, _displayType(CS_DISPLAY_MAX)
|
||||||
, _currentDecoDisplay(nullptr)
|
, _currentDecoDisplay(nullptr)
|
||||||
, _displayIndex(-1)
|
, _displayIndex(-1)
|
||||||
|
@ -59,7 +58,7 @@ DisplayManager::DisplayManager()
|
||||||
|
|
||||||
DisplayManager::~DisplayManager()
|
DisplayManager::~DisplayManager()
|
||||||
{
|
{
|
||||||
CC_SAFE_DELETE(_decoDisplayList);
|
_decoDisplayList.clear();
|
||||||
|
|
||||||
if( _displayRenderNode )
|
if( _displayRenderNode )
|
||||||
{
|
{
|
||||||
|
@ -93,14 +92,14 @@ void DisplayManager::addDisplay(DisplayData *displayData, int index)
|
||||||
{
|
{
|
||||||
DecorativeDisplay *decoDisplay = nullptr;
|
DecorativeDisplay *decoDisplay = nullptr;
|
||||||
|
|
||||||
if( (index >= 0) && (index < _decoDisplayList->count()) )
|
if( (index >= 0) && (index < _decoDisplayList.size()) )
|
||||||
{
|
{
|
||||||
decoDisplay = (DecorativeDisplay *)_decoDisplayList->getObjectAtIndex(index);
|
decoDisplay = (DecorativeDisplay *)_decoDisplayList.at(index);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
decoDisplay = DecorativeDisplay::create();
|
decoDisplay = DecorativeDisplay::create();
|
||||||
_decoDisplayList->addObject(decoDisplay);
|
_decoDisplayList.pushBack(decoDisplay);
|
||||||
}
|
}
|
||||||
|
|
||||||
DisplayFactory::addDisplay(_bone, decoDisplay, displayData);
|
DisplayFactory::addDisplay(_bone, decoDisplay, displayData);
|
||||||
|
@ -117,14 +116,14 @@ void DisplayManager::addDisplay(Node *display, int index)
|
||||||
{
|
{
|
||||||
DecorativeDisplay *decoDisplay = nullptr;
|
DecorativeDisplay *decoDisplay = nullptr;
|
||||||
|
|
||||||
if( (index >= 0) && (index < _decoDisplayList->count()) )
|
if( (index >= 0) && (index < _decoDisplayList.size()) )
|
||||||
{
|
{
|
||||||
decoDisplay = (DecorativeDisplay *)_decoDisplayList->getObjectAtIndex(index);
|
decoDisplay = _decoDisplayList.at(index);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
decoDisplay = DecorativeDisplay::create();
|
decoDisplay = DecorativeDisplay::create();
|
||||||
_decoDisplayList->addObject(decoDisplay);
|
_decoDisplayList.pushBack(decoDisplay);
|
||||||
}
|
}
|
||||||
|
|
||||||
DisplayData *displayData = nullptr;
|
DisplayData *displayData = nullptr;
|
||||||
|
@ -144,9 +143,9 @@ void DisplayManager::addDisplay(Node *display, int index)
|
||||||
{
|
{
|
||||||
bool find = false;
|
bool find = false;
|
||||||
|
|
||||||
for (int i = _decoDisplayList->count()-2; i>=0; i--)
|
for (long i = _decoDisplayList.size()-2; i>=0; i--)
|
||||||
{
|
{
|
||||||
DecorativeDisplay *dd = static_cast<DecorativeDisplay*>(_decoDisplayList->getObjectAtIndex(i));
|
DecorativeDisplay *dd = _decoDisplayList.at(i);
|
||||||
SpriteDisplayData *sdd = static_cast<SpriteDisplayData*>(dd->getDisplayData());
|
SpriteDisplayData *sdd = static_cast<SpriteDisplayData*>(dd->getDisplayData());
|
||||||
if (sdd)
|
if (sdd)
|
||||||
{
|
{
|
||||||
|
@ -179,6 +178,7 @@ void DisplayManager::addDisplay(Node *display, int index)
|
||||||
else if(Armature *armature = dynamic_cast<Armature *>(display))
|
else if(Armature *armature = dynamic_cast<Armature *>(display))
|
||||||
{
|
{
|
||||||
displayData = ArmatureDisplayData::create();
|
displayData = ArmatureDisplayData::create();
|
||||||
|
displayData->displayName = armature->getName();
|
||||||
armature->setParentBone(_bone);
|
armature->setParentBone(_bone);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
|
@ -205,17 +205,17 @@ void DisplayManager::removeDisplay(int index)
|
||||||
_displayIndex = -1;
|
_displayIndex = -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
_decoDisplayList->removeObjectAtIndex(index);
|
_decoDisplayList.erase(index);
|
||||||
}
|
}
|
||||||
|
|
||||||
Array *DisplayManager::getDecorativeDisplayList() const
|
const cocos2d::Vector<DecorativeDisplay*>& DisplayManager::getDecorativeDisplayList() const
|
||||||
{
|
{
|
||||||
return _decoDisplayList;
|
return _decoDisplayList;
|
||||||
}
|
}
|
||||||
|
|
||||||
void DisplayManager::changeDisplayByIndex(int index, bool force)
|
void DisplayManager::changeDisplayByIndex(int index, bool force)
|
||||||
{
|
{
|
||||||
CCASSERT( (_decoDisplayList ? index < (int)_decoDisplayList->count() : true), "the _index value is out of range");
|
CCASSERT( index < (int)_decoDisplayList.size(), "the _index value is out of range");
|
||||||
|
|
||||||
_forceChangeDisplay = force;
|
_forceChangeDisplay = force;
|
||||||
|
|
||||||
|
@ -238,14 +238,26 @@ void DisplayManager::changeDisplayByIndex(int index, bool force)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
DecorativeDisplay *decoDisplay = (DecorativeDisplay *)_decoDisplayList->getObjectAtIndex(_displayIndex);
|
DecorativeDisplay *decoDisplay = (DecorativeDisplay *)_decoDisplayList.at(_displayIndex);
|
||||||
|
|
||||||
setCurrentDecorativeDisplay(decoDisplay);
|
setCurrentDecorativeDisplay(decoDisplay);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void CCDisplayManager::changeDisplayByName(const char *name, bool force)
|
||||||
|
{
|
||||||
|
for (int i = 0; i<_decoDisplayList.size(); i++)
|
||||||
|
{
|
||||||
|
if (_decoDisplayList.at(i)->getDisplayData()->displayName == name)
|
||||||
|
{
|
||||||
|
changeDisplayByIndex(i, force);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
void DisplayManager::setCurrentDecorativeDisplay(DecorativeDisplay *decoDisplay)
|
void DisplayManager::setCurrentDecorativeDisplay(DecorativeDisplay *decoDisplay)
|
||||||
{
|
{
|
||||||
#if ENABLE_PHYSICS_BOX2D_DETECT || ENABLE_PHYSICS_CHIPMUNK_DETECT
|
#if ENABLE_PHYSICS_BOX2D_DETECT || ENABLE_PHYSICS_CHIPMUNK_DETECT || ENABLE_PHYSICS_SAVE_CALCULATED_VERTEX
|
||||||
if (_currentDecoDisplay && _currentDecoDisplay->getColliderDetector())
|
if (_currentDecoDisplay && _currentDecoDisplay->getColliderDetector())
|
||||||
{
|
{
|
||||||
_currentDecoDisplay->getColliderDetector()->setActive(false);
|
_currentDecoDisplay->getColliderDetector()->setActive(false);
|
||||||
|
@ -254,7 +266,7 @@ void DisplayManager::setCurrentDecorativeDisplay(DecorativeDisplay *decoDisplay)
|
||||||
|
|
||||||
_currentDecoDisplay = decoDisplay;
|
_currentDecoDisplay = decoDisplay;
|
||||||
|
|
||||||
#if ENABLE_PHYSICS_BOX2D_DETECT || ENABLE_PHYSICS_CHIPMUNK_DETECT
|
#if ENABLE_PHYSICS_BOX2D_DETECT || ENABLE_PHYSICS_CHIPMUNK_DETECT || ENABLE_PHYSICS_SAVE_CALCULATED_VERTEX
|
||||||
if (_currentDecoDisplay && _currentDecoDisplay->getColliderDetector())
|
if (_currentDecoDisplay && _currentDecoDisplay->getColliderDetector())
|
||||||
{
|
{
|
||||||
_currentDecoDisplay->getColliderDetector()->setActive(true);
|
_currentDecoDisplay->getColliderDetector()->setActive(true);
|
||||||
|
@ -325,18 +337,16 @@ DecorativeDisplay *DisplayManager::getCurrentDecorativeDisplay() const
|
||||||
|
|
||||||
DecorativeDisplay *DisplayManager::getDecorativeDisplayByIndex( int index) const
|
DecorativeDisplay *DisplayManager::getDecorativeDisplayByIndex( int index) const
|
||||||
{
|
{
|
||||||
return (DecorativeDisplay *)_decoDisplayList->getObjectAtIndex(index);
|
return _decoDisplayList.at(index);
|
||||||
}
|
}
|
||||||
|
|
||||||
void DisplayManager::initDisplayList(BoneData *boneData)
|
void DisplayManager::initDisplayList(BoneData *boneData)
|
||||||
{
|
{
|
||||||
CC_SAFE_DELETE(_decoDisplayList);
|
_decoDisplayList.clear();
|
||||||
_decoDisplayList = Array::create();
|
|
||||||
_decoDisplayList->retain();
|
|
||||||
|
|
||||||
CS_RETURN_IF(!boneData);
|
CS_RETURN_IF(!boneData);
|
||||||
|
|
||||||
for(auto object : boneData->displayDataList)
|
for(auto& object : boneData->displayDataList)
|
||||||
{
|
{
|
||||||
DisplayData *displayData = static_cast<DisplayData *>(object);
|
DisplayData *displayData = static_cast<DisplayData *>(object);
|
||||||
|
|
||||||
|
@ -345,7 +355,7 @@ void DisplayManager::initDisplayList(BoneData *boneData)
|
||||||
|
|
||||||
DisplayFactory::createDisplay(_bone, decoDisplay);
|
DisplayFactory::createDisplay(_bone, decoDisplay);
|
||||||
|
|
||||||
_decoDisplayList->addObject(decoDisplay);
|
_decoDisplayList.pushBack(decoDisplay);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -72,7 +72,7 @@ public:
|
||||||
|
|
||||||
void removeDisplay(int index);
|
void removeDisplay(int index);
|
||||||
|
|
||||||
cocos2d::Array *getDecorativeDisplayList() const;
|
const cocos2d::Vector<DecorativeDisplay*>& getDecorativeDisplayList() const;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Change display by index. You can just use this method to change display in the display list.
|
* Change display by index. You can just use this method to change display in the display list.
|
||||||
|
@ -85,6 +85,7 @@ public:
|
||||||
*/
|
*/
|
||||||
void changeDisplayByIndex(int index, bool force);
|
void changeDisplayByIndex(int index, bool force);
|
||||||
|
|
||||||
|
void changeDisplayByName(const char *name, bool force);
|
||||||
|
|
||||||
cocos2d::Node *getDisplayRenderNode() const;
|
cocos2d::Node *getDisplayRenderNode() const;
|
||||||
DisplayType getDisplayRenderNodeType() const;
|
DisplayType getDisplayRenderNodeType() const;
|
||||||
|
@ -129,7 +130,7 @@ public:
|
||||||
virtual void setForceChangeDisplay(bool force) { _forceChangeDisplay = force; }
|
virtual void setForceChangeDisplay(bool force) { _forceChangeDisplay = force; }
|
||||||
virtual bool isForceChangeDisplay() const { return _forceChangeDisplay; }
|
virtual bool isForceChangeDisplay() const { return _forceChangeDisplay; }
|
||||||
protected:
|
protected:
|
||||||
cocos2d::Array *_decoDisplayList;
|
cocos2d::Vector<DecorativeDisplay*> _decoDisplayList;
|
||||||
//! Display render node.
|
//! Display render node.
|
||||||
cocos2d::Node *_displayRenderNode;
|
cocos2d::Node *_displayRenderNode;
|
||||||
//! Display render node type
|
//! Display render node type
|
||||||
|
|
|
@ -38,16 +38,12 @@ ProcessBase::ProcessBase(void)
|
||||||
, _rawDuration(0)
|
, _rawDuration(0)
|
||||||
, _loopType(ANIMATION_LOOP_BACK)
|
, _loopType(ANIMATION_LOOP_BACK)
|
||||||
, _tweenEasing(Linear)
|
, _tweenEasing(Linear)
|
||||||
|
, _animationInternal(1/60.0f)
|
||||||
, _durationTween(0)
|
, _durationTween(0)
|
||||||
, _currentFrame(0)
|
, _currentFrame(0)
|
||||||
, _curFrameIndex(0)
|
, _curFrameIndex(0)
|
||||||
, _isLoopBack(false)
|
, _isLoopBack(false)
|
||||||
{
|
{
|
||||||
/*
|
|
||||||
* set _animationInternal defualt value to Director::getInstance()
|
|
||||||
* ->getAnimationInterval(), in line with game update speed
|
|
||||||
*/
|
|
||||||
_animationInternal = CCDirector::getInstance()->getAnimationInterval();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -73,8 +69,6 @@ void ProcessBase::stop()
|
||||||
{
|
{
|
||||||
_isComplete = true;
|
_isComplete = true;
|
||||||
_isPlaying = false;
|
_isPlaying = false;
|
||||||
_currentFrame = 0;
|
|
||||||
_currentPercent = 0;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void ProcessBase::play(int durationTo, int durationTween, int loop, int tweenEasing)
|
void ProcessBase::play(int durationTo, int durationTween, int loop, int tweenEasing)
|
||||||
|
@ -157,7 +151,7 @@ void ProcessBase::gotoFrame(int frameIndex)
|
||||||
|
|
||||||
int ProcessBase::getCurrentFrameIndex()
|
int ProcessBase::getCurrentFrameIndex()
|
||||||
{
|
{
|
||||||
_curFrameIndex = _rawDuration * _currentPercent;
|
_curFrameIndex = (_rawDuration-1) * _currentPercent;
|
||||||
return _curFrameIndex;
|
return _curFrameIndex;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -124,8 +124,6 @@ public:
|
||||||
virtual float getCurrentPercent() const { return _currentPercent; }
|
virtual float getCurrentPercent() const { return _currentPercent; }
|
||||||
virtual int getRawDuration() const { return _rawDuration; }
|
virtual int getRawDuration() const { return _rawDuration; }
|
||||||
|
|
||||||
virtual void setAnimationInternal(float animationInternal) { _animationInternal = animationInternal; }
|
|
||||||
virtual float getAnimationInternal() const { return _animationInternal; }
|
|
||||||
protected:
|
protected:
|
||||||
|
|
||||||
virtual void gotoFrame(int frameIndex);
|
virtual void gotoFrame(int frameIndex);
|
||||||
|
|
|
@ -213,6 +213,17 @@ kmMat4 Skin::getNodeToWorldTransformAR() const
|
||||||
return TransformConcat(displayTransform, _bone->getArmature()->getNodeToWorldTransform());
|
return TransformConcat(displayTransform, _bone->getArmature()->getNodeToWorldTransform());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void Skin::draw()
|
||||||
|
{
|
||||||
|
kmMat4 mv;
|
||||||
|
kmGLGetMatrix(KM_GL_MODELVIEW, &mv);
|
||||||
|
|
||||||
|
//TODO implement z order
|
||||||
|
QuadCommand* renderCommand = QuadCommand::getCommandPool().generateCommand();
|
||||||
|
renderCommand->init(0, _vertexZ, _texture->getName(), _shaderProgram, _blendFunc, &_quad, 1, mv);
|
||||||
|
Director::getInstance()->getRenderer()->addCommand(renderCommand);
|
||||||
|
}
|
||||||
|
|
||||||
void Skin::setBone(Bone *bone)
|
void Skin::setBone(Bone *bone)
|
||||||
{
|
{
|
||||||
_bone = bone;
|
_bone = bone;
|
||||||
|
|
|
@ -50,6 +50,9 @@ public:
|
||||||
|
|
||||||
kmMat4 getNodeToWorldTransform() const override;
|
kmMat4 getNodeToWorldTransform() const override;
|
||||||
kmMat4 getNodeToWorldTransformAR() const;
|
kmMat4 getNodeToWorldTransformAR() const;
|
||||||
|
|
||||||
|
virtual void draw() override;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @js NA
|
* @js NA
|
||||||
* @lua NA
|
* @lua NA
|
||||||
|
|
|
@ -141,7 +141,7 @@ void Tween::play(MovementBoneData *movementBoneData, int durationTo, int duratio
|
||||||
}
|
}
|
||||||
_frameTweenEasing = Linear;
|
_frameTweenEasing = Linear;
|
||||||
}
|
}
|
||||||
else if (_movementBoneData->frameList.count() > 1)
|
else if (_movementBoneData->frameList.size() > 1)
|
||||||
{
|
{
|
||||||
_durationTween = durationTween * _movementBoneData->scale;
|
_durationTween = durationTween * _movementBoneData->scale;
|
||||||
|
|
||||||
|
@ -176,7 +176,7 @@ void Tween::gotoAndPlay(int frameIndex)
|
||||||
_isPlaying = true;
|
_isPlaying = true;
|
||||||
_isComplete = _isPause = false;
|
_isComplete = _isPause = false;
|
||||||
|
|
||||||
_currentPercent = (float)_curFrameIndex / (float)_rawDuration;
|
_currentPercent = (float)_curFrameIndex / ((float)_rawDuration-1);
|
||||||
_currentFrame = _nextFrameIndex * _currentPercent;
|
_currentFrame = _nextFrameIndex * _currentPercent;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -338,7 +338,7 @@ void Tween::arriveKeyFrame(FrameData *keyFrameData)
|
||||||
_bone->updateZOrder();
|
_bone->updateZOrder();
|
||||||
|
|
||||||
//! Update blend type
|
//! Update blend type
|
||||||
_bone->setBlendType(keyFrameData->blendType);
|
_bone->setBlendFunc(keyFrameData->blendFunc);
|
||||||
|
|
||||||
//! Update child armature's movement
|
//! Update child armature's movement
|
||||||
Armature *childAramture = _bone->getChildArmature();
|
Armature *childAramture = _bone->getChildArmature();
|
||||||
|
@ -394,7 +394,7 @@ float Tween::updateFrameData(float currentPercent)
|
||||||
currentPercent = fmodf(currentPercent, 1);
|
currentPercent = fmodf(currentPercent, 1);
|
||||||
}
|
}
|
||||||
|
|
||||||
float playedTime = (float)_rawDuration * currentPercent;
|
float playedTime = ((float)_rawDuration-1) * currentPercent;
|
||||||
|
|
||||||
|
|
||||||
//! If play to current frame's front or back, then find current frame again
|
//! If play to current frame's front or back, then find current frame again
|
||||||
|
@ -404,25 +404,25 @@ float Tween::updateFrameData(float currentPercent)
|
||||||
* Get frame length, if _toIndex >= _length, then set _toIndex to 0, start anew.
|
* Get frame length, if _toIndex >= _length, then set _toIndex to 0, start anew.
|
||||||
* _toIndex is next index will play
|
* _toIndex is next index will play
|
||||||
*/
|
*/
|
||||||
int length = _movementBoneData->frameList.count();
|
long length = _movementBoneData->frameList.size();
|
||||||
FrameData **frames = (FrameData **)_movementBoneData->frameList.data->arr;
|
cocos2d::Vector<FrameData *> &frames = _movementBoneData->frameList;
|
||||||
|
|
||||||
FrameData *from = nullptr;
|
FrameData *from = nullptr;
|
||||||
FrameData *to = nullptr;
|
FrameData *to = nullptr;
|
||||||
|
|
||||||
if (playedTime < frames[0]->frameID)
|
if (playedTime < frames.at(0)->frameID)
|
||||||
{
|
{
|
||||||
from = to = frames[0];
|
from = to = frames.at(0);
|
||||||
setBetween(from, to);
|
setBetween(from, to);
|
||||||
return _currentPercent;
|
return _currentPercent;
|
||||||
}
|
}
|
||||||
|
|
||||||
if(playedTime >= frames[length - 1]->frameID)
|
if(playedTime >= frames.at(length - 1)->frameID)
|
||||||
{
|
{
|
||||||
// If _passLastFrame is true and playedTime >= frames[length - 1]->frameID, then do not need to go on.
|
// If _passLastFrame is true and playedTime >= frames[length - 1]->frameID, then do not need to go on.
|
||||||
if (_passLastFrame)
|
if (_passLastFrame)
|
||||||
{
|
{
|
||||||
from = to = frames[length - 1];
|
from = to = frames.at(length - 1);
|
||||||
setBetween(from, to);
|
setBetween(from, to);
|
||||||
return _currentPercent;
|
return _currentPercent;
|
||||||
}
|
}
|
||||||
|
@ -437,7 +437,7 @@ float Tween::updateFrameData(float currentPercent)
|
||||||
do
|
do
|
||||||
{
|
{
|
||||||
_fromIndex = _toIndex;
|
_fromIndex = _toIndex;
|
||||||
from = frames[_fromIndex];
|
from = frames.at(_fromIndex);
|
||||||
_totalDuration = from->frameID;
|
_totalDuration = from->frameID;
|
||||||
|
|
||||||
_toIndex = _fromIndex + 1;
|
_toIndex = _fromIndex + 1;
|
||||||
|
@ -446,7 +446,7 @@ float Tween::updateFrameData(float currentPercent)
|
||||||
_toIndex = 0;
|
_toIndex = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
to = frames[_toIndex];
|
to = frames.at(_toIndex);
|
||||||
|
|
||||||
//! Guaranteed to trigger frame event
|
//! Guaranteed to trigger frame event
|
||||||
if(from->strEvent.length() != 0 && !_animation->isIgnoreFrameEvent())
|
if(from->strEvent.length() != 0 && !_animation->isIgnoreFrameEvent())
|
||||||
|
@ -477,7 +477,7 @@ float Tween::updateFrameData(float currentPercent)
|
||||||
TweenType tweenType = (_frameTweenEasing != Linear) ? _frameTweenEasing : _tweenEasing;
|
TweenType tweenType = (_frameTweenEasing != Linear) ? _frameTweenEasing : _tweenEasing;
|
||||||
if (tweenType != TWEEN_EASING_MAX && tweenType != Linear && !_passLastFrame)
|
if (tweenType != TWEEN_EASING_MAX && tweenType != Linear && !_passLastFrame)
|
||||||
{
|
{
|
||||||
currentPercent = TweenFunction::tweenTo(0, 1, currentPercent, 1, tweenType);
|
currentPercent = TweenFunction::tweenTo(currentPercent, tweenType, _from->easingParams);
|
||||||
}
|
}
|
||||||
|
|
||||||
return currentPercent;
|
return currentPercent;
|
||||||
|
|
|
@ -25,389 +25,454 @@ THE SOFTWARE.
|
||||||
#include "cocostudio/CCTweenFunction.h"
|
#include "cocostudio/CCTweenFunction.h"
|
||||||
#include "cocostudio/CCUtilMath.h"
|
#include "cocostudio/CCUtilMath.h"
|
||||||
|
|
||||||
|
#ifndef M_PI_X_2
|
||||||
|
#define M_PI_X_2 (float)M_PI * 2.0f
|
||||||
|
#endif
|
||||||
|
|
||||||
namespace cocostudio {
|
namespace cocostudio {
|
||||||
|
|
||||||
float TweenFunction::tweenTo(float from, float change, float time, float duration, TweenType tweenType)
|
float TweenFunction::tweenTo(float time, TweenType type, float *easingParam)
|
||||||
{
|
{
|
||||||
float delta = 0;
|
float delta = 0;
|
||||||
|
|
||||||
switch (tweenType)
|
switch (type)
|
||||||
{
|
{
|
||||||
|
case CUSTOM_EASING:
|
||||||
|
delta = customEase(time, easingParam);
|
||||||
|
break;
|
||||||
|
|
||||||
case Linear:
|
case Linear:
|
||||||
delta = linear(time, 0, 1, duration);
|
delta = linear(time);
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case Sine_EaseIn:
|
case Sine_EaseIn:
|
||||||
delta = sineEaseIn(time, 0, 1, duration);
|
delta = sineEaseIn(time);
|
||||||
break;
|
break;
|
||||||
case Sine_EaseOut:
|
case Sine_EaseOut:
|
||||||
delta = sineEaseOut(time, 0, 1, duration);
|
delta = sineEaseOut(time);
|
||||||
break;
|
break;
|
||||||
case Sine_EaseInOut:
|
case Sine_EaseInOut:
|
||||||
delta = sineEaseInOut(time, 0, 1, duration);
|
delta = sineEaseInOut(time);
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case Quad_EaseIn:
|
case Quad_EaseIn:
|
||||||
delta = quadEaseIn(time, 0, 1, duration);
|
delta = quadEaseIn(time);
|
||||||
break;
|
break;
|
||||||
case Quad_EaseOut:
|
case Quad_EaseOut:
|
||||||
delta = quadEaseOut(time, 0, 1, duration);
|
delta = quadEaseOut(time);
|
||||||
break;
|
break;
|
||||||
case Quad_EaseInOut:
|
case Quad_EaseInOut:
|
||||||
delta = quadEaseInOut(time, 0, 1, duration);
|
delta = quadEaseInOut(time);
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case Cubic_EaseIn:
|
case Cubic_EaseIn:
|
||||||
delta = cubicEaseIn(time, 0, 1, duration);
|
delta = cubicEaseIn(time);
|
||||||
break;
|
break;
|
||||||
case Cubic_EaseOut:
|
case Cubic_EaseOut:
|
||||||
delta = cubicEaseOut(time, 0, 1, duration);
|
delta = cubicEaseOut(time);
|
||||||
break;
|
break;
|
||||||
case Cubic_EaseInOut:
|
case Cubic_EaseInOut:
|
||||||
delta = cubicEaseInOut(time, 0, 1, duration);
|
delta = cubicEaseInOut(time);
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case Quart_EaseIn:
|
case Quart_EaseIn:
|
||||||
delta = quartEaseIn(time, 0, 1, duration);
|
delta = quartEaseIn(time);
|
||||||
break;
|
break;
|
||||||
case Quart_EaseOut:
|
case Quart_EaseOut:
|
||||||
delta = quartEaseOut(time, 0, 1, duration);
|
delta = quartEaseOut(time);
|
||||||
break;
|
break;
|
||||||
case Quart_EaseInOut:
|
case Quart_EaseInOut:
|
||||||
delta = quartEaseInOut(time, 0, 1, duration);
|
delta = quartEaseInOut(time);
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case Quint_EaseIn:
|
case Quint_EaseIn:
|
||||||
delta = quintEaseIn(time, 0, 1, duration);
|
delta = quintEaseIn(time);
|
||||||
break;
|
break;
|
||||||
case Quint_EaseOut:
|
case Quint_EaseOut:
|
||||||
delta = quintEaseOut(time, 0, 1, duration);
|
delta = quintEaseOut(time);
|
||||||
break;
|
break;
|
||||||
case Quint_EaseInOut:
|
case Quint_EaseInOut:
|
||||||
delta = quintEaseInOut(time, 0, 1, duration);
|
delta = quintEaseInOut(time);
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case Expo_EaseIn:
|
case Expo_EaseIn:
|
||||||
delta = expoEaseIn(time, 0, 1, duration);
|
delta = expoEaseIn(time);
|
||||||
break;
|
break;
|
||||||
case Expo_EaseOut:
|
case Expo_EaseOut:
|
||||||
delta = expoEaseOut(time, 0, 1, duration);
|
delta = expoEaseOut(time);
|
||||||
break;
|
break;
|
||||||
case Expo_EaseInOut:
|
case Expo_EaseInOut:
|
||||||
delta = expoEaseInOut(time, 0, 1, duration);
|
delta = expoEaseInOut(time);
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case Circ_EaseIn:
|
case Circ_EaseIn:
|
||||||
delta = circEaseIn(time, 0, 1, duration);
|
delta = circEaseIn(time);
|
||||||
break;
|
break;
|
||||||
case Circ_EaseOut:
|
case Circ_EaseOut:
|
||||||
delta = circEaseOut(time, 0, 1, duration);
|
delta = circEaseOut(time);
|
||||||
break;
|
break;
|
||||||
case Circ_EaseInOut:
|
case Circ_EaseInOut:
|
||||||
delta = circEaseInOut(time, 0, 1, duration);
|
delta = circEaseInOut(time);
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case Elastic_EaseIn:
|
case Elastic_EaseIn:
|
||||||
delta = elasticEaseIn(time, 0, 1, duration);
|
delta = elasticEaseIn(time, easingParam);
|
||||||
break;
|
break;
|
||||||
case Elastic_EaseOut:
|
case Elastic_EaseOut:
|
||||||
delta = elasticEaseOut(time, 0, 1, duration);
|
delta = elasticEaseOut(time, easingParam);
|
||||||
break;
|
break;
|
||||||
case Elastic_EaseInOut:
|
case Elastic_EaseInOut:
|
||||||
delta = elasticEaseInOut(time, 0, 1, duration);
|
delta = elasticEaseInOut(time, easingParam);
|
||||||
break;
|
break;
|
||||||
|
|
||||||
|
|
||||||
case Back_EaseIn:
|
case Back_EaseIn:
|
||||||
delta = backEaseIn(time, 0, 1, duration);
|
delta = backEaseIn(time);
|
||||||
break;
|
break;
|
||||||
case Back_EaseOut:
|
case Back_EaseOut:
|
||||||
delta = backEaseOut(time, 0, 1, duration);
|
delta = backEaseOut(time);
|
||||||
break;
|
break;
|
||||||
case Back_EaseInOut:
|
case Back_EaseInOut:
|
||||||
delta = backEaseInOut(time, 0, 1, duration);
|
delta = backEaseInOut(time);
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case Bounce_EaseIn:
|
case Bounce_EaseIn:
|
||||||
delta = bounceEaseIn(time, 0, 1, duration);
|
delta = bounceEaseIn(time);
|
||||||
break;
|
break;
|
||||||
case Bounce_EaseOut:
|
case Bounce_EaseOut:
|
||||||
delta = bounceEaseOut(time, 0, 1, duration);
|
delta = bounceEaseOut(time);
|
||||||
break;
|
break;
|
||||||
case Bounce_EaseInOut:
|
case Bounce_EaseInOut:
|
||||||
delta = bounceEaseInOut(time, 0, 1, duration);
|
delta = bounceEaseInOut(time);
|
||||||
break;
|
break;
|
||||||
|
|
||||||
default:
|
default:
|
||||||
delta = sineEaseInOut(time, 0, 1, duration);
|
delta = sineEaseInOut(time);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
return delta;
|
return delta;
|
||||||
}
|
}
|
||||||
|
|
||||||
float TweenFunction::linear(float t, float b, float c, float d)
|
// Linear
|
||||||
|
float TweenFunction::linear(float time)
|
||||||
{
|
{
|
||||||
return c * t / d + b;
|
return time;
|
||||||
}
|
}
|
||||||
|
|
||||||
float TweenFunction::quadEaseIn(float t, float b, float c, float d)
|
|
||||||
|
// Sine Ease
|
||||||
|
float TweenFunction::sineEaseIn(float time)
|
||||||
{
|
{
|
||||||
t /= d;
|
return -1 * cosf(time * (float)M_PI_2) + 1;
|
||||||
return c * t * t + b;
|
|
||||||
}
|
}
|
||||||
float TweenFunction::quadEaseOut(float t, float b, float c, float d)
|
float TweenFunction::sineEaseOut(float time)
|
||||||
{
|
{
|
||||||
t /= d;
|
return sinf(time * (float)M_PI_2);
|
||||||
return -c * t * (t - 2) + b;
|
|
||||||
}
|
}
|
||||||
float TweenFunction::quadEaseInOut(float t, float b, float c, float d)
|
float TweenFunction::sineEaseInOut(float time)
|
||||||
{
|
{
|
||||||
t = t/d*2;
|
return -0.5f * (cosf((float)M_PI * time) - 1);
|
||||||
if ((t) < 1)
|
|
||||||
return c / 2 * t * t + b;
|
|
||||||
--t;
|
|
||||||
return -c / 2 * (t * (t - 2) - 1) + b;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
float TweenFunction::cubicEaseIn(float t, float b, float c, float d)
|
|
||||||
|
// Quad Ease
|
||||||
|
float TweenFunction::quadEaseIn(float time)
|
||||||
{
|
{
|
||||||
t /= d;
|
return time * time;
|
||||||
return c * t * t * t + b;
|
|
||||||
}
|
}
|
||||||
float TweenFunction::cubicEaseOut(float t, float b, float c, float d)
|
float TweenFunction::quadEaseOut(float time)
|
||||||
{
|
{
|
||||||
t = t / d - 1;
|
return -1 * time * (time - 2);
|
||||||
return c * (t * t * t + 1) + b;
|
|
||||||
}
|
}
|
||||||
float TweenFunction::cubicEaseInOut(float t, float b, float c, float d)
|
float TweenFunction::quadEaseInOut(float time)
|
||||||
{
|
{
|
||||||
t = t/d*2;
|
time = time*2;
|
||||||
if ((t) < 1)
|
if (time < 1)
|
||||||
return c / 2 * t * t * t + b;
|
return 0.5f * time * time;
|
||||||
t -= 2;
|
--time;
|
||||||
return c / 2 * (t * t * t + 2) + b;
|
return -0.5f * (time * (time - 2) - 1);
|
||||||
}
|
}
|
||||||
|
|
||||||
float TweenFunction::quartEaseIn(float t, float b, float c, float d)
|
|
||||||
|
|
||||||
|
// Cubic Ease
|
||||||
|
float TweenFunction::cubicEaseIn(float time)
|
||||||
{
|
{
|
||||||
t /= d;
|
return time * time * time;
|
||||||
return c * t * t * t * t + b;
|
|
||||||
}
|
}
|
||||||
float TweenFunction::quartEaseOut(float t, float b, float c, float d)
|
float TweenFunction::cubicEaseOut(float time)
|
||||||
{
|
{
|
||||||
t = t / d - 1;
|
time -= 1;
|
||||||
return -c * (t * t * t * t - 1) + b;
|
return (time * time * time + 1);
|
||||||
}
|
}
|
||||||
float TweenFunction::quartEaseInOut(float t, float b, float c, float d)
|
float TweenFunction::cubicEaseInOut(float time)
|
||||||
{
|
{
|
||||||
t = t/d*2;
|
time = time*2;
|
||||||
if ((t) < 1)
|
if (time < 1)
|
||||||
return c / 2 * t * t * t * t + b;
|
return 0.5f * time * time * time;
|
||||||
t -= 2;
|
time -= 2;
|
||||||
return -c / 2 * (t * t * t * t - 2) + b;
|
return 0.5f * (time * time * time + 2);
|
||||||
}
|
}
|
||||||
|
|
||||||
float TweenFunction::quintEaseIn(float t, float b, float c, float d)
|
|
||||||
|
// Quart Ease
|
||||||
|
float TweenFunction::quartEaseIn(float time)
|
||||||
{
|
{
|
||||||
t /= d;
|
return time * time * time * time;
|
||||||
return c * t * t * t * t * t + b;
|
|
||||||
}
|
}
|
||||||
float TweenFunction::quintEaseOut(float t, float b, float c, float d)
|
float TweenFunction::quartEaseOut(float time)
|
||||||
{
|
{
|
||||||
t = t / d - 1;
|
time -= 1;
|
||||||
return c * (t * t * t * t * t + 1) + b;
|
return -(time * time * time * time - 1);
|
||||||
}
|
}
|
||||||
float TweenFunction::quintEaseInOut(float t, float b, float c, float d)
|
float TweenFunction::quartEaseInOut(float time)
|
||||||
{
|
{
|
||||||
t = t/d*2;
|
time = time*2;
|
||||||
if ((t) < 1)
|
if (time < 1)
|
||||||
return c / 2 * t * t * t * t * t + b;
|
return 0.5f * time * time * time * time;
|
||||||
t -= 2;
|
time -= 2;
|
||||||
return c / 2 * (t * t * t * t * t + 2) + b;
|
return -0.5f * (time * time * time * time - 2);
|
||||||
}
|
}
|
||||||
|
|
||||||
float TweenFunction::sineEaseIn(float t, float b, float c, float d)
|
|
||||||
|
// Quint Ease
|
||||||
|
float TweenFunction::quintEaseIn(float time)
|
||||||
{
|
{
|
||||||
return -c * cos(t / d * (M_PI / 2)) + c + b;
|
return time * time * time * time * time;
|
||||||
}
|
}
|
||||||
float TweenFunction::sineEaseOut(float t, float b, float c, float d)
|
float TweenFunction::quintEaseOut(float time)
|
||||||
{
|
{
|
||||||
return c * sin(t / d * (M_PI / 2)) + b;
|
time -=1;
|
||||||
|
return (time * time * time * time * time + 1);
|
||||||
}
|
}
|
||||||
float TweenFunction::sineEaseInOut(float t, float b, float c, float d)
|
float TweenFunction::quintEaseInOut(float time)
|
||||||
{
|
{
|
||||||
return -c / 2 * (cos(M_PI * t / d) - 1) + b;
|
time = time*2;
|
||||||
|
if (time < 1)
|
||||||
|
return 0.5f * time * time * time * time * time;
|
||||||
|
time -= 2;
|
||||||
|
return 0.5f * (time * time * time * time * time + 2);
|
||||||
}
|
}
|
||||||
|
|
||||||
float TweenFunction::expoEaseIn(float t, float b, float c, float d)
|
|
||||||
{
|
|
||||||
return (t == 0) ? b : c * pow(2, 10 * (t / d - 1)) + b;
|
|
||||||
}
|
|
||||||
float TweenFunction::expoEaseOut(float t, float b, float c, float d)
|
|
||||||
{
|
|
||||||
return (t == d) ? b + c : c * (-pow(2, -10 * t / d) + 1) + b;
|
|
||||||
}
|
|
||||||
float TweenFunction::expoEaseInOut(float t, float b, float c, float d)
|
|
||||||
{
|
|
||||||
if (t == 0)
|
|
||||||
return b;
|
|
||||||
if (t == d)
|
|
||||||
return b + c;
|
|
||||||
if ((t /= d / 2) < 1)
|
|
||||||
return c / 2 * pow(2, 10 * (t - 1)) + b;
|
|
||||||
--t;
|
|
||||||
return c / 2 * (-pow(2, -10 * t) + 2) + b;
|
|
||||||
}
|
|
||||||
|
|
||||||
float TweenFunction::circEaseIn(float t, float b, float c, float d)
|
// Expo Ease
|
||||||
|
float TweenFunction::expoEaseIn(float time)
|
||||||
{
|
{
|
||||||
t /= d;
|
return time == 0 ? 0 : powf(2, 10 * (time/1 - 1)) - 1 * 0.001f;
|
||||||
return -c * (sqrt(1 - t * t) - 1) + b;
|
|
||||||
}
|
}
|
||||||
float TweenFunction::circEaseOut(float t, float b, float c, float d)
|
float TweenFunction::expoEaseOut(float time)
|
||||||
{
|
{
|
||||||
t = t / d - 1;
|
return time == 1 ? 1 : (-powf(2, -10 * time / 1) + 1);
|
||||||
return c * sqrt(1 - t * t) + b;
|
|
||||||
}
|
}
|
||||||
float TweenFunction::circEaseInOut(float t, float b, float c, float d)
|
float TweenFunction::expoEaseInOut(float time)
|
||||||
{
|
{
|
||||||
t = t/d*2;
|
time /= 0.5f;
|
||||||
if ((t) < 1)
|
if (time < 1)
|
||||||
return -c / 2 * (sqrt(1 - t * t) - 1) + b;
|
|
||||||
t -= 2;
|
|
||||||
return c / 2 * (sqrt(1 - t * t) + 1) + b;
|
|
||||||
}
|
|
||||||
|
|
||||||
float TweenFunction::elasticEaseIn(float t, float b, float c, float d, float a, float p)
|
|
||||||
{
|
|
||||||
float s = 0;
|
|
||||||
if (t == 0)
|
|
||||||
return b;
|
|
||||||
t /= d;
|
|
||||||
if (t == 1)
|
|
||||||
return b + c;
|
|
||||||
if (!p)
|
|
||||||
p = d * .3;
|
|
||||||
if (!a || a < abs(c))
|
|
||||||
{
|
{
|
||||||
a = c;
|
time = 0.5f * powf(2, 10 * (time - 1));
|
||||||
s = p / 4;
|
|
||||||
}
|
|
||||||
else
|
|
||||||
s = p / (2 * M_PI) * asin(c / a);
|
|
||||||
t -= 1;
|
|
||||||
return -(a * pow(2, 10 * t) * sin((t * d - s) * (2 * M_PI) / p)) + b;
|
|
||||||
}
|
|
||||||
float TweenFunction::elasticEaseOut(float t, float b, float c, float d, float a, float p)
|
|
||||||
{
|
|
||||||
float s = 0;
|
|
||||||
if (t == 0)
|
|
||||||
return b;
|
|
||||||
t /= d;
|
|
||||||
if (t == 1)
|
|
||||||
return b + c;
|
|
||||||
if (!p)
|
|
||||||
p = d * .3;
|
|
||||||
if (!a || a < abs(c))
|
|
||||||
{
|
|
||||||
a = c;
|
|
||||||
s = p / 4;
|
|
||||||
}
|
|
||||||
else
|
|
||||||
s = p / (2 * M_PI) * asin(c / a);
|
|
||||||
return (a * pow(2, -10 * t) * sin((t * d - s) * (2 * M_PI) / p) + c + b);
|
|
||||||
}
|
|
||||||
float TweenFunction::elasticEaseInOut(float t, float b, float c, float d, float a, float p)
|
|
||||||
{
|
|
||||||
float s = 0;
|
|
||||||
if (t == 0)
|
|
||||||
return b;
|
|
||||||
t = t/d*2;
|
|
||||||
if ((t) == 2)
|
|
||||||
return b + c;
|
|
||||||
if (!p)
|
|
||||||
p = d * (.3 * 1.5);
|
|
||||||
if (!a || a < abs(c))
|
|
||||||
{
|
|
||||||
a = c;
|
|
||||||
s = p / 4;
|
|
||||||
}
|
|
||||||
else
|
|
||||||
s = p / (2 * M_PI) * asin(c / a);
|
|
||||||
if (t < 1)
|
|
||||||
{
|
|
||||||
t -= 1;
|
|
||||||
return -.5 * (a * pow(2, 10 * t) * sin((t * d - s) * (2 * M_PI) / p)) + b;
|
|
||||||
}
|
|
||||||
t -= 1;
|
|
||||||
return a * pow(2, -10 * t) * sin((t * d - s) * (2 * M_PI) / p) * .5 + c + b;
|
|
||||||
}
|
|
||||||
|
|
||||||
float TweenFunction::backEaseIn(float t, float b, float c, float d, float s)
|
|
||||||
{
|
|
||||||
if (s == 0)
|
|
||||||
s = 1.70158f;
|
|
||||||
t /= d;
|
|
||||||
return c * t * t * ((s + 1) * t - s) + b;
|
|
||||||
}
|
|
||||||
float TweenFunction::backEaseOut(float t, float b, float c, float d, float s)
|
|
||||||
{
|
|
||||||
if (s == 0)
|
|
||||||
s = 1.70158f;
|
|
||||||
t = t / d - 1;
|
|
||||||
return c * (t * t * ((s + 1) * t + s) + 1) + b;
|
|
||||||
}
|
|
||||||
float TweenFunction::backEaseInOut(float t, float b, float c, float d, float s)
|
|
||||||
{
|
|
||||||
if (s == 0)
|
|
||||||
s = 1.70158f;
|
|
||||||
if ((t /= d / 2) < 1)
|
|
||||||
{
|
|
||||||
s *= (1.525f);
|
|
||||||
return c / 2 * (t * t * ((s + 1) * t - s)) + b;
|
|
||||||
}
|
|
||||||
|
|
||||||
t -= 2;
|
|
||||||
s *= (1.525f);
|
|
||||||
return c / 2 * (t * t * ((s + 1) * t + s) + 2) + b;
|
|
||||||
}
|
|
||||||
|
|
||||||
float TweenFunction::bounceEaseIn(float t, float b, float c, float d)
|
|
||||||
{
|
|
||||||
return c - bounceEaseOut(d - t, 0, c, d) + b;
|
|
||||||
}
|
|
||||||
|
|
||||||
float TweenFunction::bounceEaseOut(float t, float b, float c, float d)
|
|
||||||
{
|
|
||||||
t /= d;
|
|
||||||
if (t < (1 / 2.75f))
|
|
||||||
{
|
|
||||||
return c * (7.5625f * t * t) + b;
|
|
||||||
}
|
|
||||||
else if (t < (2 / 2.75f))
|
|
||||||
{
|
|
||||||
t -= (1.5f / 2.75f);
|
|
||||||
return c * (7.5625f * t * t + .75f) + b;
|
|
||||||
}
|
|
||||||
else if (t < (2.5f / 2.75f))
|
|
||||||
{
|
|
||||||
t -= (2.25f / 2.75f);
|
|
||||||
return c * (7.5625f * t * t + .9375f) + b;
|
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
t -= (2.625f / 2.75f);
|
time = 0.5f * (-powf(2, -10 * (time - 1)) + 2);
|
||||||
return c * (7.5625f * t * t + .984375f) + b;
|
}
|
||||||
|
|
||||||
|
return time;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
// Circ Ease
|
||||||
|
float TweenFunction::circEaseIn(float time)
|
||||||
|
{
|
||||||
|
return -1 * (sqrt(1 - time * time) - 1);
|
||||||
|
}
|
||||||
|
float TweenFunction::circEaseOut(float time)
|
||||||
|
{
|
||||||
|
time = time - 1;
|
||||||
|
return sqrt(1 - time * time);
|
||||||
|
}
|
||||||
|
float TweenFunction::circEaseInOut(float time)
|
||||||
|
{
|
||||||
|
time = time * 2;
|
||||||
|
if (time < 1)
|
||||||
|
return -0.5f * (sqrt(1 - time * time) - 1);
|
||||||
|
time -= 2;
|
||||||
|
return 0.5f * (sqrt(1 - time * time) + 1);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
// Elastic Ease
|
||||||
|
float TweenFunction::elasticEaseIn(float time, float *easingParam)
|
||||||
|
{
|
||||||
|
float period = 0.3f;
|
||||||
|
|
||||||
|
if (easingParam != NULL)
|
||||||
|
{
|
||||||
|
period = easingParam[0];
|
||||||
|
}
|
||||||
|
|
||||||
|
float newT = 0;
|
||||||
|
if (time == 0 || time == 1)
|
||||||
|
{
|
||||||
|
newT = time;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
float s = period / 4;
|
||||||
|
time = time - 1;
|
||||||
|
newT = -powf(2, 10 * time) * sinf((time - s) * M_PI_X_2 / period);
|
||||||
|
}
|
||||||
|
|
||||||
|
return newT;
|
||||||
|
}
|
||||||
|
float TweenFunction::elasticEaseOut(float time, float *easingParam)
|
||||||
|
{
|
||||||
|
float period = 0.3f;
|
||||||
|
|
||||||
|
if (easingParam != NULL)
|
||||||
|
{
|
||||||
|
period = easingParam[0];
|
||||||
|
}
|
||||||
|
|
||||||
|
float newT = 0;
|
||||||
|
if (time == 0 || time == 1)
|
||||||
|
{
|
||||||
|
newT = time;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
float s = period / 4;
|
||||||
|
newT = powf(2, -10 * time) * sinf((time - s) * M_PI_X_2 / period) + 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
return newT;
|
||||||
|
}
|
||||||
|
float TweenFunction::elasticEaseInOut(float time, float *easingParam)
|
||||||
|
{
|
||||||
|
float period = 0.3f;
|
||||||
|
|
||||||
|
if (easingParam != NULL)
|
||||||
|
{
|
||||||
|
period = easingParam[0];
|
||||||
|
}
|
||||||
|
|
||||||
|
float newT = 0;
|
||||||
|
if (time == 0 || time == 1)
|
||||||
|
{
|
||||||
|
newT = time;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
time = time * 2;
|
||||||
|
if (! period)
|
||||||
|
{
|
||||||
|
period = 0.3f * 1.5f;
|
||||||
|
}
|
||||||
|
|
||||||
|
float s = period / 4;
|
||||||
|
|
||||||
|
time = time - 1;
|
||||||
|
if (time < 0)
|
||||||
|
{
|
||||||
|
newT = -0.5f * powf(2, 10 * time) * sinf((time -s) * M_PI_X_2 / period);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
newT = powf(2, -10 * time) * sinf((time - s) * M_PI_X_2 / period) * 0.5f + 1;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return newT;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
// Back Ease
|
||||||
|
float TweenFunction::backEaseIn(float time)
|
||||||
|
{
|
||||||
|
float overshoot = 1.70158f;
|
||||||
|
return time * time * ((overshoot + 1) * time - overshoot);
|
||||||
|
}
|
||||||
|
float TweenFunction::backEaseOut(float time)
|
||||||
|
{
|
||||||
|
float overshoot = 1.70158f;
|
||||||
|
|
||||||
|
time = time - 1;
|
||||||
|
return time * time * ((overshoot + 1) * time + overshoot) + 1;
|
||||||
|
}
|
||||||
|
float TweenFunction::backEaseInOut(float time)
|
||||||
|
{
|
||||||
|
float overshoot = 1.70158f * 1.525f;
|
||||||
|
|
||||||
|
time = time * 2;
|
||||||
|
if (time < 1)
|
||||||
|
{
|
||||||
|
return (time * time * ((overshoot + 1) * time - overshoot)) / 2;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
time = time - 2;
|
||||||
|
return (time * time * ((overshoot + 1) * time + overshoot)) / 2 + 1;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
float TweenFunction::bounceEaseInOut(float t, float b, float c, float d)
|
|
||||||
|
|
||||||
|
// Bounce Ease
|
||||||
|
float bounceTime(float time)
|
||||||
{
|
{
|
||||||
if (t < d / 2)
|
if (time < 1 / 2.75)
|
||||||
return bounceEaseIn(t * 2, 0, c, d) * .5 + b;
|
{
|
||||||
|
return 7.5625f * time * time;
|
||||||
|
} else
|
||||||
|
if (time < 2 / 2.75)
|
||||||
|
{
|
||||||
|
time -= 1.5f / 2.75f;
|
||||||
|
return 7.5625f * time * time + 0.75f;
|
||||||
|
} else
|
||||||
|
if(time < 2.5 / 2.75)
|
||||||
|
{
|
||||||
|
time -= 2.25f / 2.75f;
|
||||||
|
return 7.5625f * time * time + 0.9375f;
|
||||||
|
}
|
||||||
|
|
||||||
|
time -= 2.625f / 2.75f;
|
||||||
|
return 7.5625f * time * time + 0.984375f;
|
||||||
|
}
|
||||||
|
float TweenFunction::bounceEaseIn(float time)
|
||||||
|
{
|
||||||
|
return 1 - bounceTime(1 - time);
|
||||||
|
}
|
||||||
|
|
||||||
|
float TweenFunction::bounceEaseOut(float time)
|
||||||
|
{
|
||||||
|
return bounceTime(time);
|
||||||
|
}
|
||||||
|
|
||||||
|
float TweenFunction::bounceEaseInOut(float time)
|
||||||
|
{
|
||||||
|
float newT = 0;
|
||||||
|
if (time < 0.5f)
|
||||||
|
{
|
||||||
|
time = time * 2;
|
||||||
|
newT = (1 - bounceTime(1 - time)) * 0.5f;
|
||||||
|
}
|
||||||
else
|
else
|
||||||
return bounceEaseOut(t * 2 - d, 0, c, d) * .5 + c * .5 + b;
|
{
|
||||||
|
newT = bounceTime(time * 2 - 1) * 0.5f + 0.5f;
|
||||||
|
}
|
||||||
|
|
||||||
|
return newT;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
// Custom Ease
|
||||||
|
float TweenFunction::customEase(float time, float *easingParam)
|
||||||
|
{
|
||||||
|
if (easingParam)
|
||||||
|
{
|
||||||
|
float tt = 1-time;
|
||||||
|
return easingParam[1]*tt*tt*tt + 3*easingParam[3]*time*tt*tt + 3*easingParam[5]*time*time*tt + easingParam[7]*time*time*time;
|
||||||
|
}
|
||||||
|
return time;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -33,7 +33,7 @@ namespace cocostudio {
|
||||||
|
|
||||||
enum TweenType
|
enum TweenType
|
||||||
{
|
{
|
||||||
TWEEN_EASING_MIN = -1,
|
CUSTOM_EASING = -1,
|
||||||
|
|
||||||
Linear,
|
Linear,
|
||||||
|
|
||||||
|
@ -41,6 +41,7 @@ enum TweenType
|
||||||
Sine_EaseOut,
|
Sine_EaseOut,
|
||||||
Sine_EaseInOut,
|
Sine_EaseInOut,
|
||||||
|
|
||||||
|
|
||||||
Quad_EaseIn,
|
Quad_EaseIn,
|
||||||
Quad_EaseOut,
|
Quad_EaseOut,
|
||||||
Quad_EaseInOut,
|
Quad_EaseInOut,
|
||||||
|
@ -80,56 +81,58 @@ enum TweenType
|
||||||
TWEEN_EASING_MAX = 10000
|
TWEEN_EASING_MAX = 10000
|
||||||
};
|
};
|
||||||
/**
|
/**
|
||||||
* @js NA
|
* @js NA
|
||||||
* @lua NA
|
* @lua NA
|
||||||
*/
|
*/
|
||||||
class TweenFunction
|
class TweenFunction
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
|
|
||||||
static float tweenTo(float from, float change, float time, float duration, TweenType tweenType);
|
static float tweenTo(float time, TweenType type, float *easingParam);
|
||||||
|
|
||||||
static float linear(float t, float b, float c, float d);
|
static float linear(float time);
|
||||||
|
|
||||||
static float sineEaseIn(float t, float b, float c, float d);
|
static float sineEaseIn(float time);
|
||||||
static float sineEaseOut(float t, float b, float c, float d);
|
static float sineEaseOut(float time);
|
||||||
static float sineEaseInOut(float t, float b, float c, float d);
|
static float sineEaseInOut(float time);
|
||||||
|
|
||||||
static float quadEaseIn(float t, float b, float c, float d);
|
static float quadEaseIn(float time);
|
||||||
static float quadEaseOut(float t, float b, float c, float d);
|
static float quadEaseOut(float time);
|
||||||
static float quadEaseInOut(float t, float b, float c, float d);
|
static float quadEaseInOut(float time);
|
||||||
|
|
||||||
static float cubicEaseIn(float t, float b, float c, float d);
|
static float cubicEaseIn(float time);
|
||||||
static float cubicEaseOut(float t, float b, float c, float d);
|
static float cubicEaseOut(float time);
|
||||||
static float cubicEaseInOut(float t, float b, float c, float d);
|
static float cubicEaseInOut(float time);
|
||||||
|
|
||||||
static float quartEaseIn(float t, float b, float c, float d);
|
static float quartEaseIn(float time);
|
||||||
static float quartEaseOut(float t, float b, float c, float d);
|
static float quartEaseOut(float time);
|
||||||
static float quartEaseInOut(float t, float b, float c, float d);
|
static float quartEaseInOut(float time);
|
||||||
|
|
||||||
static float quintEaseIn(float t, float b, float c, float d);
|
static float quintEaseIn(float time);
|
||||||
static float quintEaseOut(float t, float b, float c, float d);
|
static float quintEaseOut(float time);
|
||||||
static float quintEaseInOut(float t, float b, float c, float d);
|
static float quintEaseInOut(float time);
|
||||||
|
|
||||||
static float expoEaseIn(float t, float b, float c, float d);
|
static float expoEaseIn(float time);
|
||||||
static float expoEaseOut(float t, float b, float c, float d);
|
static float expoEaseOut(float time);
|
||||||
static float expoEaseInOut(float t, float b, float c, float d);
|
static float expoEaseInOut(float time);
|
||||||
|
|
||||||
static float circEaseIn(float t, float b, float c, float d);
|
static float circEaseIn(float time);
|
||||||
static float circEaseOut(float t, float b, float c, float d);
|
static float circEaseOut(float time);
|
||||||
static float circEaseInOut(float t, float b, float c, float d);
|
static float circEaseInOut(float time);
|
||||||
|
|
||||||
static float elasticEaseIn(float t, float b, float c, float d, float a = 0, float p = 0);
|
static float elasticEaseIn(float time, float *easingParam);
|
||||||
static float elasticEaseOut(float t, float b, float c, float d, float a = 0, float p = 0);
|
static float elasticEaseOut(float time, float *easingParam);
|
||||||
static float elasticEaseInOut(float t, float b, float c, float d, float a = 0, float p = 0);
|
static float elasticEaseInOut(float time, float *easingParam);
|
||||||
|
|
||||||
static float backEaseIn(float t, float b, float c, float d, float s = 0);
|
static float backEaseIn(float time);
|
||||||
static float backEaseOut(float t, float b, float c, float d, float s = 0);
|
static float backEaseOut(float time);
|
||||||
static float backEaseInOut(float t, float b, float c, float d, float s = 0);
|
static float backEaseInOut(float time);
|
||||||
|
|
||||||
static float bounceEaseIn(float t, float b, float c, float d);
|
static float bounceEaseIn(float time);
|
||||||
static float bounceEaseOut(float t, float b, float c, float d);
|
static float bounceEaseOut(float time);
|
||||||
static float bounceEaseInOut(float t, float b, float c, float d);
|
static float bounceEaseInOut(float time);
|
||||||
|
|
||||||
|
static float customEase(float time, float *easingParam);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -51,7 +51,7 @@ Layer *CreateLayer(int index)
|
||||||
case TEST_USE_DIFFERENT_PICTURE:
|
case TEST_USE_DIFFERENT_PICTURE:
|
||||||
pLayer = new TestUseMutiplePicture();
|
pLayer = new TestUseMutiplePicture();
|
||||||
break;
|
break;
|
||||||
case TEST_BCOLLIDER_DETECTOR:
|
case TEST_COLLIDER_DETECTOR:
|
||||||
pLayer = new TestColliderDetector();
|
pLayer = new TestColliderDetector();
|
||||||
break;
|
break;
|
||||||
case TEST_BOUDINGBOX:
|
case TEST_BOUDINGBOX:
|
||||||
|
@ -66,6 +66,15 @@ Layer *CreateLayer(int index)
|
||||||
case TEST_ARMATURE_NESTING_2:
|
case TEST_ARMATURE_NESTING_2:
|
||||||
pLayer = new TestArmatureNesting2();
|
pLayer = new TestArmatureNesting2();
|
||||||
break;
|
break;
|
||||||
|
case TEST_PLAY_SEVERAL_MOVEMENT:
|
||||||
|
pLayer = new TestPlaySeveralMovement();
|
||||||
|
break;
|
||||||
|
case TEST_EASING:
|
||||||
|
pLayer = new TestEasing();
|
||||||
|
break;
|
||||||
|
case TEST_CHANGE_ANIMATION_INTERNAL:
|
||||||
|
pLayer = new TestChangeAnimationInternal();
|
||||||
|
break;
|
||||||
default:
|
default:
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
@ -251,15 +260,7 @@ void TestAsynchronousLoading::onEnter()
|
||||||
ArmatureDataManager::getInstance()->addArmatureFileInfoAsync("armature/horse.ExportJson", this, schedule_selector(TestAsynchronousLoading::dataLoaded));
|
ArmatureDataManager::getInstance()->addArmatureFileInfoAsync("armature/horse.ExportJson", this, schedule_selector(TestAsynchronousLoading::dataLoaded));
|
||||||
ArmatureDataManager::getInstance()->addArmatureFileInfoAsync("armature/bear.ExportJson", this, schedule_selector(TestAsynchronousLoading::dataLoaded));
|
ArmatureDataManager::getInstance()->addArmatureFileInfoAsync("armature/bear.ExportJson", this, schedule_selector(TestAsynchronousLoading::dataLoaded));
|
||||||
ArmatureDataManager::getInstance()->addArmatureFileInfoAsync("armature/HeroAnimation.ExportJson", this, schedule_selector(TestAsynchronousLoading::dataLoaded));
|
ArmatureDataManager::getInstance()->addArmatureFileInfoAsync("armature/HeroAnimation.ExportJson", this, schedule_selector(TestAsynchronousLoading::dataLoaded));
|
||||||
|
ArmatureDataManager::getInstance()->addArmatureFileInfoAsync("armature/testEasing.ExportJson", this, schedule_selector(TestAsynchronousLoading::dataLoaded));
|
||||||
//! load data directly
|
|
||||||
// ArmatureDataManager::getInstance()->addArmatureFileInfo("armature/knight.png", "armature/knight.plist", "armature/knight.xml");
|
|
||||||
// ArmatureDataManager::getInstance()->addArmatureFileInfo("armature/weapon.png", "armature/weapon.plist", "armature/weapon.xml");
|
|
||||||
// ArmatureDataManager::getInstance()->addArmatureFileInfo("armature/robot.png", "armature/robot.plist", "armature/robot.xml");
|
|
||||||
// ArmatureDataManager::getInstance()->addArmatureFileInfo("armature/cyborg.png", "armature/cyborg.plist", "armature/cyborg.xml");
|
|
||||||
// ArmatureDataManager::getInstance()->addArmatureFileInfo("armature/Dragon.png", "armature/Dragon.plist", "armature/Dragon.xml");
|
|
||||||
// ArmatureDataManager::getInstance()->addArmatureFileInfo("armature/Cowboy.ExportJson");
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
std::string TestAsynchronousLoading::title() const
|
std::string TestAsynchronousLoading::title() const
|
||||||
|
@ -526,7 +527,7 @@ void TestAnimationEvent::onEnter()
|
||||||
* Set armature's movement event callback function
|
* Set armature's movement event callback function
|
||||||
* To disconnect this event, just setMovementEventCallFunc(nullptr, nullptr);
|
* To disconnect this event, just setMovementEventCallFunc(nullptr, nullptr);
|
||||||
*/
|
*/
|
||||||
armature->getAnimation()->setMovementEventCallFunc(this, movementEvent_selector(TestAnimationEvent::animationEvent));
|
armature->getAnimation()->setMovementEventCallFunc(CC_CALLBACK_0(TestAnimationEvent::animationEvent, this, std::placeholders::_1, std::placeholders::_2, std::placeholders::_3));
|
||||||
addChild(armature);
|
addChild(armature);
|
||||||
}
|
}
|
||||||
std::string TestAnimationEvent::title() const
|
std::string TestAnimationEvent::title() const
|
||||||
|
@ -580,10 +581,9 @@ void TestFrameEvent::onEnter()
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Set armature's frame event callback function
|
* Set armature's frame event callback function
|
||||||
* To disconnect this event, just setFrameEventCallFunc(nullptr, nullptr);
|
* To disconnect this event, just setFrameEventCallFunc(nullptr);
|
||||||
*/
|
*/
|
||||||
armature->getAnimation()->setFrameEventCallFunc(this, frameEvent_selector(TestFrameEvent::onFrameEvent));
|
armature->getAnimation()->setFrameEventCallFunc(CC_CALLBACK_0(TestFrameEvent::onFrameEvent, this, std::placeholders::_1, std::placeholders::_2, std::placeholders::_3, std::placeholders::_4));
|
||||||
|
|
||||||
addChild(armature);
|
addChild(armature);
|
||||||
|
|
||||||
schedule( schedule_selector(TestFrameEvent::checkAction) );
|
schedule( schedule_selector(TestFrameEvent::checkAction) );
|
||||||
|
@ -750,10 +750,9 @@ void TestColliderDetector::onEnter()
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Set armature's frame event callback function
|
* Set armature's frame event callback function
|
||||||
* To disconnect this event, just setFrameEventCallFunc(nullptr, nullptr);
|
* To disconnect this event, just setFrameEventCallFunc(nullptr);
|
||||||
*/
|
*/
|
||||||
armature->getAnimation()->setFrameEventCallFunc(this, frameEvent_selector(TestColliderDetector::onFrameEvent));
|
armature->getAnimation()->setFrameEventCallFunc(CC_CALLBACK_0(TestColliderDetector::onFrameEvent, this, std::placeholders::_1, std::placeholders::_2, std::placeholders::_3, std::placeholders::_4));
|
||||||
|
|
||||||
addChild(armature);
|
addChild(armature);
|
||||||
|
|
||||||
armature2 = Armature::create("Cowboy");
|
armature2 = Armature::create("Cowboy");
|
||||||
|
@ -763,7 +762,11 @@ void TestColliderDetector::onEnter()
|
||||||
armature2->setPosition(Point(VisibleRect::right().x - 60, VisibleRect::left().y));
|
armature2->setPosition(Point(VisibleRect::right().x - 60, VisibleRect::left().y));
|
||||||
addChild(armature2);
|
addChild(armature2);
|
||||||
|
|
||||||
|
#if ENABLE_PHYSICS_BOX2D_DETECT || ENABLE_PHYSICS_CHIPMUNK_DETECT
|
||||||
bullet = cocos2d::extension::PhysicsSprite::createWithSpriteFrameName("25.png");
|
bullet = cocos2d::extension::PhysicsSprite::createWithSpriteFrameName("25.png");
|
||||||
|
#elif ENABLE_PHYSICS_SAVE_CALCULATED_VERTEX
|
||||||
|
bullet = Sprite::createWithSpriteFrameName("25.png");
|
||||||
|
#endif
|
||||||
addChild(bullet);
|
addChild(bullet);
|
||||||
|
|
||||||
initWorld();
|
initWorld();
|
||||||
|
@ -846,7 +849,7 @@ void TestColliderDetector::onExit()
|
||||||
}
|
}
|
||||||
void TestColliderDetector::draw()
|
void TestColliderDetector::draw()
|
||||||
{
|
{
|
||||||
ccGLEnableVertexAttribs( kCCVertexAttribFlag_Position );
|
GL::enableVertexAttribs( GL::VERTEX_ATTRIB_FLAG_POSITION );
|
||||||
kmGLPushMatrix();
|
kmGLPushMatrix();
|
||||||
world->DrawDebugData();
|
world->DrawDebugData();
|
||||||
kmGLPopMatrix();
|
kmGLPopMatrix();
|
||||||
|
@ -861,8 +864,7 @@ void TestColliderDetector::update(float delta)
|
||||||
{
|
{
|
||||||
Contact &contact = *it;
|
Contact &contact = *it;
|
||||||
|
|
||||||
Bone *ba = (Bone *)contact.fixtureA->GetUserData();
|
Bone *bb = static_cast<Bone *>(contact.fixtureB->GetUserData);
|
||||||
Bone *bb = (Bone *)contact.fixtureB->GetUserData();
|
|
||||||
|
|
||||||
bb->getArmature()->setVisible(false);
|
bb->getArmature()->setVisible(false);
|
||||||
}
|
}
|
||||||
|
@ -1013,6 +1015,62 @@ void TestColliderDetector::initWorld()
|
||||||
|
|
||||||
cpSpaceAddCollisionHandler(space, eEnemyTag, eBulletTag, beginHit, nullptr, nullptr, endHit, nullptr);
|
cpSpaceAddCollisionHandler(space, eEnemyTag, eBulletTag, beginHit, nullptr, nullptr, endHit, nullptr);
|
||||||
}
|
}
|
||||||
|
#elif ENABLE_PHYSICS_SAVE_CALCULATED_VERTEX
|
||||||
|
void TestColliderDetector::update(float delta)
|
||||||
|
{
|
||||||
|
armature2->setVisible(true);
|
||||||
|
|
||||||
|
Rect rect = bullet->getBoundingBox();
|
||||||
|
|
||||||
|
// This code is just telling how to get the vertex.
|
||||||
|
// For a more accurate collider detection, you need to implemente yourself.
|
||||||
|
const Map<std::string, Bone*>& map = armature2->getBoneDic();
|
||||||
|
for(auto element : map)
|
||||||
|
{
|
||||||
|
Bone *bone = element.second;
|
||||||
|
ColliderDetector *detector = bone->getColliderDetector();
|
||||||
|
|
||||||
|
if (!detector)
|
||||||
|
continue;
|
||||||
|
|
||||||
|
const cocos2d::Vector<ColliderBody*>& bodyList = detector->getColliderBodyList();
|
||||||
|
|
||||||
|
for (auto object : bodyList)
|
||||||
|
{
|
||||||
|
ColliderBody *body = static_cast<ColliderBody*>(object);
|
||||||
|
const std::vector<Point> &vertexList = body->getCalculatedVertexList();
|
||||||
|
|
||||||
|
float minx, miny, maxx, maxy = 0;
|
||||||
|
int length = vertexList.size();
|
||||||
|
for (int i = 0; i<length; i++)
|
||||||
|
{
|
||||||
|
Point vertex = vertexList.at(i);
|
||||||
|
if (i == 0)
|
||||||
|
{
|
||||||
|
minx = maxx = vertex.x;
|
||||||
|
miny = maxy = vertex.y;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
minx = vertex.x < minx ? vertex.x : minx;
|
||||||
|
miny = vertex.y < miny ? vertex.y : miny;
|
||||||
|
maxx = vertex.x > maxx ? vertex.x : maxx;
|
||||||
|
maxy = vertex.y > maxy ? vertex.y : maxy;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
Rect temp = Rect(minx, miny, maxx - minx, maxy - miny);
|
||||||
|
|
||||||
|
if (temp.intersectsRect(rect))
|
||||||
|
{
|
||||||
|
armature2->setVisible(false);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
void TestColliderDetector::draw()
|
||||||
|
{
|
||||||
|
armature2->drawContour();
|
||||||
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
|
||||||
|
@ -1293,3 +1351,122 @@ Armature * TestArmatureNesting2::createMount(const char *name, Point position)
|
||||||
return armature;
|
return armature;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
void TestPlaySeveralMovement::onEnter()
|
||||||
|
{
|
||||||
|
ArmatureTestLayer::onEnter();
|
||||||
|
|
||||||
|
auto listener = EventListenerTouchAllAtOnce::create();
|
||||||
|
listener->onTouchesEnded = CC_CALLBACK_2(TestPlaySeveralMovement::onTouchesEnded, this);
|
||||||
|
_eventDispatcher->addEventListenerWithSceneGraphPriority(listener, this);
|
||||||
|
|
||||||
|
std::string name[] = {"Walk", "FireMax", "Fire"};
|
||||||
|
std::vector<std::string> names(name, name+3);
|
||||||
|
// int index[] = {0, 1, 2};
|
||||||
|
// std::vector<int> indexes(index, index+3);
|
||||||
|
|
||||||
|
Armature *armature = NULL;
|
||||||
|
armature = Armature::create("Cowboy");
|
||||||
|
armature->getAnimation()->play(names);
|
||||||
|
// armature->getAnimation()->playByIndex(indexes);
|
||||||
|
armature->setScale(0.2f);
|
||||||
|
|
||||||
|
armature->setPosition(Point(VisibleRect::center().x, VisibleRect::center().y/*-100*/));
|
||||||
|
addChild(armature);
|
||||||
|
}
|
||||||
|
std::string TestPlaySeveralMovement::title() const
|
||||||
|
{
|
||||||
|
return "Test play several movement";
|
||||||
|
}
|
||||||
|
|
||||||
|
std::string TestPlaySeveralMovement::subtitle()const
|
||||||
|
{
|
||||||
|
return "Movement is played one by one";
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
void TestEasing::onEnter()
|
||||||
|
{
|
||||||
|
ArmatureTestLayer::onEnter();
|
||||||
|
|
||||||
|
auto listener = EventListenerTouchAllAtOnce::create();
|
||||||
|
listener->onTouchesEnded = CC_CALLBACK_2(TestPlaySeveralMovement::onTouchesEnded, this);
|
||||||
|
_eventDispatcher->addEventListenerWithSceneGraphPriority(listener, this);
|
||||||
|
|
||||||
|
animationID = 0;
|
||||||
|
|
||||||
|
armature = Armature::create("testEasing");
|
||||||
|
armature->getAnimation()->playByIndex(0);
|
||||||
|
armature->setScale(0.8f);
|
||||||
|
|
||||||
|
armature->setPosition(Point(VisibleRect::center().x, VisibleRect::center().y));
|
||||||
|
addChild(armature);
|
||||||
|
|
||||||
|
updateSubTitle();
|
||||||
|
}
|
||||||
|
|
||||||
|
std::string TestEasing::title() const
|
||||||
|
{
|
||||||
|
return "Test easing effect";
|
||||||
|
}
|
||||||
|
std::string TestEasing::subtitle() const
|
||||||
|
{
|
||||||
|
return "Current easing : ";
|
||||||
|
}
|
||||||
|
void TestEasing::onTouchesEnded(const std::vector<Touch*>& touches, Event* event)
|
||||||
|
{
|
||||||
|
animationID++;
|
||||||
|
animationID = animationID % armature->getAnimation()->getMovementCount();
|
||||||
|
armature->getAnimation()->playByIndex(animationID);
|
||||||
|
|
||||||
|
updateSubTitle();
|
||||||
|
}
|
||||||
|
void TestEasing::updateSubTitle()
|
||||||
|
{
|
||||||
|
std::string str = subtitle() + armature->getAnimation()->getCurrentMovementID();
|
||||||
|
LabelTTF *label = (LabelTTF *)getChildByTag(10001);
|
||||||
|
label->setString(str.c_str());
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
void TestChangeAnimationInternal::onEnter()
|
||||||
|
{
|
||||||
|
ArmatureTestLayer::onEnter();
|
||||||
|
|
||||||
|
auto listener = EventListenerTouchAllAtOnce::create();
|
||||||
|
listener->onTouchesEnded = CC_CALLBACK_2(TestPlaySeveralMovement::onTouchesEnded, this);
|
||||||
|
_eventDispatcher->addEventListenerWithSceneGraphPriority(listener, this);
|
||||||
|
|
||||||
|
Armature *armature = NULL;
|
||||||
|
armature = Armature::create("Cowboy");
|
||||||
|
armature->getAnimation()->playByIndex(0);
|
||||||
|
armature->setScale(0.2f);
|
||||||
|
|
||||||
|
armature->setPosition(Point(VisibleRect::center().x, VisibleRect::center().y));
|
||||||
|
addChild(armature);
|
||||||
|
}
|
||||||
|
void TestChangeAnimationInternal::onExit()
|
||||||
|
{
|
||||||
|
Director::getInstance()->setAnimationInterval(1/60.0f);
|
||||||
|
}
|
||||||
|
std::string TestChangeAnimationInternal::title()
|
||||||
|
{
|
||||||
|
return "Test change animation internal";
|
||||||
|
}
|
||||||
|
std::string TestChangeAnimationInternal::subtitle()
|
||||||
|
{
|
||||||
|
return "Touch to change animation internal";
|
||||||
|
}
|
||||||
|
void TestChangeAnimationInternal::onTouchesEnded(const std::vector<Touch*>& touches, Event* event)
|
||||||
|
{
|
||||||
|
if (Director::getInstance()->getAnimationInterval() == 1/30.0f)
|
||||||
|
{
|
||||||
|
Director::getInstance()->setAnimationInterval(1/60.0f);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
Director::getInstance()->setAnimationInterval(1/30.0f);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
|
@ -37,11 +37,14 @@ enum {
|
||||||
TEST_FRAME_EVENT,
|
TEST_FRAME_EVENT,
|
||||||
TEST_PARTICLE_DISPLAY,
|
TEST_PARTICLE_DISPLAY,
|
||||||
TEST_USE_DIFFERENT_PICTURE,
|
TEST_USE_DIFFERENT_PICTURE,
|
||||||
TEST_BCOLLIDER_DETECTOR,
|
TEST_COLLIDER_DETECTOR,
|
||||||
TEST_BOUDINGBOX,
|
TEST_BOUDINGBOX,
|
||||||
TEST_ANCHORPOINT,
|
TEST_ANCHORPOINT,
|
||||||
TEST_ARMATURE_NESTING,
|
TEST_ARMATURE_NESTING,
|
||||||
TEST_ARMATURE_NESTING_2,
|
TEST_ARMATURE_NESTING_2,
|
||||||
|
TEST_PLAY_SEVERAL_MOVEMENT,
|
||||||
|
TEST_EASING,
|
||||||
|
TEST_CHANGE_ANIMATION_INTERNAL,
|
||||||
|
|
||||||
TEST_LAYER_COUNT
|
TEST_LAYER_COUNT
|
||||||
};
|
};
|
||||||
|
@ -257,6 +260,25 @@ public:
|
||||||
|
|
||||||
void destroyCPBody(cpBody *body);
|
void destroyCPBody(cpBody *body);
|
||||||
};
|
};
|
||||||
|
#elif ENABLE_PHYSICS_SAVE_CALCULATED_VERTEX
|
||||||
|
class TestColliderDetector : public ArmatureTestLayer
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
~TestColliderDetector();
|
||||||
|
|
||||||
|
virtual void onEnter();
|
||||||
|
virtual std::string title() const override;
|
||||||
|
virtual void update(float delta);
|
||||||
|
virtual void draw();
|
||||||
|
|
||||||
|
void onFrameEvent(cocostudio::Bone *bone, const char *evt, int originFrameIndex, int currentFrameIndex);
|
||||||
|
|
||||||
|
void initWorld() {};
|
||||||
|
cocostudio::Armature *armature;
|
||||||
|
cocostudio::Armature *armature2;
|
||||||
|
|
||||||
|
cocos2d::Sprite *bullet;
|
||||||
|
};
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
|
||||||
|
@ -327,4 +349,39 @@ public:
|
||||||
|
|
||||||
bool touchedMenu;
|
bool touchedMenu;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
class TestPlaySeveralMovement : public ArmatureTestLayer
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
virtual void onEnter();
|
||||||
|
virtual std::string title() const override;
|
||||||
|
virtual std::string subtitle() const override;
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
|
class TestEasing : public ArmatureTestLayer
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
virtual void onEnter();
|
||||||
|
virtual std::string title() const override;
|
||||||
|
virtual std::string subtitle() const override;
|
||||||
|
|
||||||
|
void onTouchesEnded(const std::vector<Touch*>& touches, Event* event);
|
||||||
|
void updateSubTitle();
|
||||||
|
|
||||||
|
int animationID;
|
||||||
|
cocostudio::Armature *armature;
|
||||||
|
};
|
||||||
|
|
||||||
|
class TestChangeAnimationInternal : public ArmatureTestLayer
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
virtual void onEnter();
|
||||||
|
virtual void onExit();
|
||||||
|
virtual std::string title();
|
||||||
|
virtual std::string subtitle();
|
||||||
|
|
||||||
|
void onTouchesEnded(const std::vector<Touch*>& touches, Event* event);
|
||||||
|
};
|
||||||
|
|
||||||
#endif // __HELLOWORLD_SCENE_H__
|
#endif // __HELLOWORLD_SCENE_H__
|
||||||
|
|
Loading…
Reference in New Issue