From 6fc0eaf5b1674f3b480f2e5a5675191c507cadb6 Mon Sep 17 00:00:00 2001 From: yinkaile <501251991@qq.com> Date: Sun, 7 Jul 2013 17:27:42 +0800 Subject: [PATCH] update --- extensions/CCArmature/CCArmature.cpp | 9 +++++++ extensions/CCArmature/CCArmature.h | 6 +++-- extensions/CCArmature/animation/CCTween.cpp | 16 ++++++------- extensions/CCArmature/animation/CCTween.h | 2 +- extensions/CCArmature/datas/CCDatas.cpp | 24 +++++++++++++++++-- extensions/CCArmature/datas/CCDatas.h | 5 +++- .../CCArmature/display/CCDisplayFactory.cpp | 2 +- extensions/CCArmature/display/CCSkin.cpp | 12 ++++++++++ extensions/CCArmature/display/CCSkin.h | 1 + .../utils/CCSpriteFrameCacheHelper.cpp | 23 +++++++++++------- .../utils/CCSpriteFrameCacheHelper.h | 4 +++- 11 files changed, 79 insertions(+), 25 deletions(-) diff --git a/extensions/CCArmature/CCArmature.cpp b/extensions/CCArmature/CCArmature.cpp index bfd0fcbf64..20222afe01 100644 --- a/extensions/CCArmature/CCArmature.cpp +++ b/extensions/CCArmature/CCArmature.cpp @@ -413,6 +413,15 @@ void CCArmature::updateOffsetPoint() } } +void CCArmature::setAnimation(CCArmatureAnimation *animation) +{ + m_pAnimation = animation; +} + +CCArmatureAnimation *CCArmature::getAnimation() +{ + return m_pAnimation; +} void CCArmature::update(float dt) { diff --git a/extensions/CCArmature/CCArmature.h b/extensions/CCArmature/CCArmature.h index 997e1e63ed..b015f16ee8 100644 --- a/extensions/CCArmature/CCArmature.h +++ b/extensions/CCArmature/CCArmature.h @@ -123,6 +123,8 @@ public: inline void setBlendFunc(ccBlendFunc blendFunc) { m_sBlendFunc = blendFunc; } inline ccBlendFunc getBlendFunc(void) { return m_sBlendFunc; } + virtual void setAnimation(CCArmatureAnimation *animation); + virtual CCArmatureAnimation *getAnimation(); protected: /* @@ -130,8 +132,6 @@ protected: */ CCBone *createBone(const char *boneName ); - - CC_SYNTHESIZE_RETAIN(CCArmatureAnimation *, m_pAnimation, Animation); CC_SYNTHESIZE(CCArmatureData *, m_pArmatureData, ArmatureData); @@ -152,6 +152,8 @@ protected: ccBlendFunc m_sBlendFunc; //! It's required for CCTextureProtocol inheritance CCPoint m_pOffsetPoint; + + CCArmatureAnimation *m_pAnimation; }; NS_CC_EXT_END diff --git a/extensions/CCArmature/animation/CCTween.cpp b/extensions/CCArmature/animation/CCTween.cpp index ec21561e9b..a43ff4ad24 100644 --- a/extensions/CCArmature/animation/CCTween.cpp +++ b/extensions/CCArmature/animation/CCTween.cpp @@ -104,7 +104,7 @@ void CCTween::play(CCMovementBoneData *movementBoneData, int durationTo, int dur m_pCurrentKeyFrame = NULL; m_iTotalDuration = 0; - betweenDuration = 0; + m_BetweenDuration = 0; m_iToIndex = 0; bool difMovement = movementBoneData != m_pMovementBoneData; @@ -200,7 +200,7 @@ void CCTween::updateHandler() m_iNextFrameIndex = m_iDurationTween; m_fCurrentFrame = m_fCurrentPercent * m_iNextFrameIndex; m_iTotalDuration = 0; - betweenDuration = 0; + m_BetweenDuration = 0; m_iToIndex = 0; break; } @@ -227,7 +227,7 @@ void CCTween::updateHandler() } m_iTotalDuration = 0; - betweenDuration = 0; + m_BetweenDuration = 0; m_iToIndex = 0; } break; @@ -243,7 +243,7 @@ void CCTween::updateHandler() m_fCurrentFrame = fmodf(m_fCurrentFrame, m_iNextFrameIndex); m_iTotalDuration = 0; - betweenDuration = 0; + m_BetweenDuration = 0; m_iToIndex = 0; } break; @@ -375,7 +375,7 @@ float CCTween::updateFrameData(float currentPrecent, bool activeFrame) bool isListEnd; //! If play to current frame's front or back, then find current frame again - if (playedTime >= m_iTotalDuration || playedTime < m_iTotalDuration - betweenDuration) + if (playedTime >= m_iTotalDuration || playedTime < m_iTotalDuration - m_BetweenDuration) { /* * Get frame length, if m_iToIndex >= _length, then set m_iToIndex to 0, start anew. @@ -384,8 +384,8 @@ float CCTween::updateFrameData(float currentPrecent, bool activeFrame) int length = m_pMovementBoneData->frameList.count(); do { - betweenDuration = m_pMovementBoneData->getFrameData(m_iToIndex)->duration; - m_iTotalDuration += betweenDuration; + m_BetweenDuration = m_pMovementBoneData->getFrameData(m_iToIndex)->duration; + m_iTotalDuration += m_BetweenDuration; m_iFromIndex = m_iToIndex; if (++m_iToIndex >= length) @@ -413,7 +413,7 @@ float CCTween::updateFrameData(float currentPrecent, bool activeFrame) setBetween(from, to); } - currentPrecent = 1 - (m_iTotalDuration - playedTime) / (float)betweenDuration; + currentPrecent = 1 - (m_iTotalDuration - playedTime) / (float)m_BetweenDuration; /* diff --git a/extensions/CCArmature/animation/CCTween.h b/extensions/CCArmature/animation/CCTween.h index 328a8d250c..b968fb6183 100644 --- a/extensions/CCArmature/animation/CCTween.h +++ b/extensions/CCArmature/animation/CCTween.h @@ -130,7 +130,7 @@ protected: CCTweenType m_eFrameTweenEasing; //! Dedermine which tween effect current frame use - int betweenDuration; //! Current key frame will last betweenDuration frames + int m_BetweenDuration; //! Current key frame will last m_BetweenDuration frames int m_iTotalDuration; diff --git a/extensions/CCArmature/datas/CCDatas.cpp b/extensions/CCArmature/datas/CCDatas.cpp index 54a6a533b8..e6ce61d295 100644 --- a/extensions/CCArmature/datas/CCDatas.cpp +++ b/extensions/CCArmature/datas/CCDatas.cpp @@ -122,6 +122,19 @@ void CCBaseData::subtract(CCBaseData *from, CCBaseData *to) } } +void CCBaseData::setColor(ccColor4B &color) +{ + r = color.r; + g = color.g; + b = color.b; + a = color.a; +} + +ccColor4B CCBaseData::getColor() +{ + return ccc4(r, g, b, a); +} + const char *CCDisplayData::changeDisplayToTexture(const char *displayName) { @@ -242,13 +255,12 @@ CCArmatureData::~CCArmatureData() bool CCArmatureData::init() { - return boneList.init(); + return true; } void CCArmatureData::addBoneData(CCBoneData *boneData) { boneDataDic.setObject(boneData, boneData->name); - boneList.addObject(boneData); } CCBoneData *CCArmatureData::getBoneData(const char *boneName) @@ -385,6 +397,14 @@ bool CCContourData::init() { return vertexList.init(); } +void CCContourData::addVertex(CCPoint *vertex) +{ + CCContourVertex2 *vertex2 = new CCContourVertex2(vertex->x, vertex->y); + vertex2->autorelease(); + + vertexList.addObject(vertex2); +} + CCTextureData::CCTextureData() : height(0.0f) diff --git a/extensions/CCArmature/datas/CCDatas.h b/extensions/CCArmature/datas/CCDatas.h index 9af512f676..81dcb29181 100644 --- a/extensions/CCArmature/datas/CCDatas.h +++ b/extensions/CCArmature/datas/CCDatas.h @@ -81,6 +81,9 @@ public: * @param to to CCBaseData */ virtual void subtract(CCBaseData *_from, CCBaseData *_to); + + virtual void setColor(ccColor4B &color); + virtual ccColor4B getColor(); public: float x; //! position x attribute float y; //! position y attribute @@ -268,7 +271,6 @@ public: public: std::string name; CCDictionary boneDataDic; - CCArray boneList; float dataVersion; }; @@ -420,6 +422,7 @@ public: ~CCContourData(void); virtual bool init(); + virtual void addVertex(CCPoint *vertex); public: CCArray vertexList; //! Save contour vertex info, vertex saved in a CCPoint }; diff --git a/extensions/CCArmature/display/CCDisplayFactory.cpp b/extensions/CCArmature/display/CCDisplayFactory.cpp index efc9fc0334..d03fb2254d 100644 --- a/extensions/CCArmature/display/CCDisplayFactory.cpp +++ b/extensions/CCArmature/display/CCDisplayFactory.cpp @@ -143,7 +143,7 @@ void CCDisplayFactory::createSpriteDisplay(CCBone *bone, CCDecorativeDisplay *de skin = CCSkin::createWithSpriteFrameName((textureName + ".png").c_str()); } - CCTextureAtlas *atlas = CCSpriteFrameCacheHelper::sharedSpriteFrameCacheHelper()->getTextureAtlas((textureName + ".png").c_str()); + CCTextureAtlas *atlas = CCSpriteFrameCacheHelper::sharedSpriteFrameCacheHelper()->getTextureAtlasWithDisplayName((textureName + ".png").c_str()); skin->setTextureAtlas(atlas); CCTextureData *textureData = CCArmatureDataManager::sharedArmatureDataManager()->getTextureData(textureName.c_str()); diff --git a/extensions/CCArmature/display/CCSkin.cpp b/extensions/CCArmature/display/CCSkin.cpp index 2aeb12b83d..967cbab6ae 100644 --- a/extensions/CCArmature/display/CCSkin.cpp +++ b/extensions/CCArmature/display/CCSkin.cpp @@ -57,6 +57,18 @@ CCSkin *CCSkin::createWithSpriteFrameName(const char *pszSpriteFrameName) return NULL; } +CCSkin *CCSkin::create(const char *pszFileName) +{ + CCSkin *skin = new CCSkin(); + if(skin && skin->initWithFile(pszFileName)) + { + skin->autorelease(); + return skin; + } + CC_SAFE_DELETE(skin); + return NULL; +} + CCSkin::CCSkin() : m_pBone(NULL) { diff --git a/extensions/CCArmature/display/CCSkin.h b/extensions/CCArmature/display/CCSkin.h index 4c145f2ea6..7dcbd112b2 100644 --- a/extensions/CCArmature/display/CCSkin.h +++ b/extensions/CCArmature/display/CCSkin.h @@ -35,6 +35,7 @@ class CCSkin : public CCSprite public: static CCSkin *create(); static CCSkin *createWithSpriteFrameName(const char *pszSpriteFrameName); + static CCSkin *create(const char *pszFileName); public: CCSkin(); diff --git a/extensions/CCArmature/utils/CCSpriteFrameCacheHelper.cpp b/extensions/CCArmature/utils/CCSpriteFrameCacheHelper.cpp index d1fc75f41f..176a182e1b 100644 --- a/extensions/CCArmature/utils/CCSpriteFrameCacheHelper.cpp +++ b/extensions/CCArmature/utils/CCSpriteFrameCacheHelper.cpp @@ -157,17 +157,22 @@ const char *CCSpriteFrameCacheHelper::getDisplayImagePath(const char *displayNam } -CCTextureAtlas *CCSpriteFrameCacheHelper::getTextureAtlas(const char *displayName) +CCTextureAtlas *CCSpriteFrameCacheHelper::getTextureAtlasWithImageName(const char *imageName) { - const char *textureName = getDisplayImagePath(displayName); - CCTextureAtlas *atlas = (CCTextureAtlas *)m_pDisplay2TextureAtlas->objectForKey(textureName); - if (atlas == NULL) - { - atlas = CCTextureAtlas::createWithTexture(CCTextureCache::sharedTextureCache()->addImage(textureName), 4); - m_pDisplay2TextureAtlas->setObject(atlas, textureName); - } + CCTextureAtlas *atlas = (CCTextureAtlas*)m_pDisplay2TextureAtlas->objectForKey(imageName); + if (atlas == NULL) + { + atlas = CCTextureAtlas::createWithTexture(CCTextureCache::sharedTextureCache()->addImage(imageName), 4); + m_pDisplay2TextureAtlas->setObject(atlas, imageName); + } - return atlas; + return atlas; +} + +CCTextureAtlas *CCSpriteFrameCacheHelper::getTextureAtlasWithDisplayName(const char *displayName) +{ + const char *textureName = getDisplayImagePath(displayName); + return getTextureAtlasWithImageName(textureName); } CCSpriteFrameCacheHelper::CCSpriteFrameCacheHelper() diff --git a/extensions/CCArmature/utils/CCSpriteFrameCacheHelper.h b/extensions/CCArmature/utils/CCSpriteFrameCacheHelper.h index b65976c8b6..66b47b9897 100644 --- a/extensions/CCArmature/utils/CCSpriteFrameCacheHelper.h +++ b/extensions/CCArmature/utils/CCSpriteFrameCacheHelper.h @@ -51,7 +51,9 @@ public: * Get this display in which image */ const char *getDisplayImagePath(const char *displayName); - CCTextureAtlas *getTextureAtlas(const char *displayName); + + cocos2d::CCTextureAtlas *getTextureAtlasWithImageName(const char *imageName); + cocos2d::CCTextureAtlas *getTextureAtlasWithDisplayName(const char *displayName); private: CCSpriteFrameCacheHelper();