add more feature and fixed some bugs.

This commit is contained in:
wu shengjin 2013-03-19 16:36:23 +08:00
parent a8030588f8
commit 1b880f0d4f
2 changed files with 48 additions and 6 deletions

View File

@ -12,6 +12,22 @@
#define FULL_PATH(a) CCFileUtils::sharedFileUtils()->fullPathFromRelativePath(a)
CCSpineNode::CCSpineNode()
{
m_skeletonJson = 0;
m_skeleton = 0;
m_animation = 0;
m_animTimer = 0;
m_loop = true;
}
CCSpineNode::~CCSpineNode()
{
CC_SAFE_DELETE(m_animation);
CC_SAFE_DELETE(m_skeleton);
CC_SAFE_DELETE(m_skeletonJson);
}
CCSpineNode* CCSpineNode::createWithFileNames(const char* skeletonFileName, const char* atlasFileName)
{
@ -39,11 +55,7 @@ bool CCSpineNode::initWithFiles(const char* skeletonFileName, const char* atlasF
m_skeleton = new Skeleton(skeletonData);
m_skeleton->setToBindPose();
m_skeleton->updateWorldTransform();
m_animTimer = 0.0f;
m_animation = 0;
m_loop = true;
setShaderProgram(CCShaderCache::sharedShaderCache()->programForKey(kCCShader_PositionTextureColor));
scheduleUpdate();
@ -53,6 +65,10 @@ bool CCSpineNode::initWithFiles(const char* skeletonFileName, const char* atlasF
void CCSpineNode::playAnimation(const char* fileName, bool loop)
{
if (m_animName == fileName
&& !isCurrAnimOver())
return;
CC_SAFE_DELETE(m_animation);
std::ifstream animationFile(FULL_PATH(fileName));
@ -80,6 +96,23 @@ void CCSpineNode::draw()
if (m_skeleton)
m_skeleton->draw();
CCNode::draw();
}
void CCSpineNode::setFlipX(bool flip)
{
if (m_skeleton)
m_skeleton->flipX = flip;
}
void CCSpineNode::setFlipY(bool flip)
{
if (m_skeleton)
m_skeleton->flipY = flip;
}
bool CCSpineNode::isCurrAnimOver() const
{
return !m_loop && m_animation && m_animation->duration <= m_animTimer;
}

View File

@ -19,6 +19,9 @@ USING_NS_CC;
class CCSpineNode : public CCNode {
public:
CCSpineNode();
virtual ~CCSpineNode();
static CCSpineNode* createWithFileNames(const char* skeletonFileName, const char* atlasFileName);
bool initWithFiles(const char* skeletonFileName, const char* atlasFileName);
@ -26,6 +29,11 @@ public:
void update(float dt);
void draw();
void setFlipX(bool flip);
void setFlipY(bool flip);
bool isCurrAnimOver() const;
private:
SkeletonJson* m_skeletonJson;
Skeleton* m_skeleton;
@ -33,6 +41,7 @@ private:
float m_animTimer;
bool m_loop;
std::string m_animName;
};
#endif /* defined(__SpineExample__CCSpineNode__) */