mirror of
https://github.com/EsotericSoftware/spine-runtimes.git
synced 2026-02-04 14:24:53 +08:00
add more feature and fixed some bugs.
This commit is contained in:
parent
a8030588f8
commit
1b880f0d4f
@ -12,6 +12,22 @@
|
|||||||
|
|
||||||
#define FULL_PATH(a) CCFileUtils::sharedFileUtils()->fullPathFromRelativePath(a)
|
#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)
|
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 = new Skeleton(skeletonData);
|
||||||
m_skeleton->setToBindPose();
|
m_skeleton->setToBindPose();
|
||||||
m_skeleton->updateWorldTransform();
|
m_skeleton->updateWorldTransform();
|
||||||
|
|
||||||
m_animTimer = 0.0f;
|
|
||||||
m_animation = 0;
|
|
||||||
m_loop = true;
|
|
||||||
|
|
||||||
setShaderProgram(CCShaderCache::sharedShaderCache()->programForKey(kCCShader_PositionTextureColor));
|
setShaderProgram(CCShaderCache::sharedShaderCache()->programForKey(kCCShader_PositionTextureColor));
|
||||||
|
|
||||||
scheduleUpdate();
|
scheduleUpdate();
|
||||||
@ -53,6 +65,10 @@ bool CCSpineNode::initWithFiles(const char* skeletonFileName, const char* atlasF
|
|||||||
|
|
||||||
void CCSpineNode::playAnimation(const char* fileName, bool loop)
|
void CCSpineNode::playAnimation(const char* fileName, bool loop)
|
||||||
{
|
{
|
||||||
|
if (m_animName == fileName
|
||||||
|
&& !isCurrAnimOver())
|
||||||
|
return;
|
||||||
|
|
||||||
CC_SAFE_DELETE(m_animation);
|
CC_SAFE_DELETE(m_animation);
|
||||||
|
|
||||||
std::ifstream animationFile(FULL_PATH(fileName));
|
std::ifstream animationFile(FULL_PATH(fileName));
|
||||||
@ -80,6 +96,23 @@ void CCSpineNode::draw()
|
|||||||
|
|
||||||
if (m_skeleton)
|
if (m_skeleton)
|
||||||
m_skeleton->draw();
|
m_skeleton->draw();
|
||||||
|
|
||||||
CCNode::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;
|
||||||
|
}
|
||||||
|
|||||||
@ -19,6 +19,9 @@ USING_NS_CC;
|
|||||||
|
|
||||||
class CCSpineNode : public CCNode {
|
class CCSpineNode : public CCNode {
|
||||||
public:
|
public:
|
||||||
|
CCSpineNode();
|
||||||
|
virtual ~CCSpineNode();
|
||||||
|
|
||||||
static CCSpineNode* createWithFileNames(const char* skeletonFileName, const char* atlasFileName);
|
static CCSpineNode* createWithFileNames(const char* skeletonFileName, const char* atlasFileName);
|
||||||
bool initWithFiles(const char* skeletonFileName, const char* atlasFileName);
|
bool initWithFiles(const char* skeletonFileName, const char* atlasFileName);
|
||||||
|
|
||||||
@ -26,6 +29,11 @@ public:
|
|||||||
|
|
||||||
void update(float dt);
|
void update(float dt);
|
||||||
void draw();
|
void draw();
|
||||||
|
|
||||||
|
void setFlipX(bool flip);
|
||||||
|
void setFlipY(bool flip);
|
||||||
|
|
||||||
|
bool isCurrAnimOver() const;
|
||||||
private:
|
private:
|
||||||
SkeletonJson* m_skeletonJson;
|
SkeletonJson* m_skeletonJson;
|
||||||
Skeleton* m_skeleton;
|
Skeleton* m_skeleton;
|
||||||
@ -33,6 +41,7 @@ private:
|
|||||||
|
|
||||||
float m_animTimer;
|
float m_animTimer;
|
||||||
bool m_loop;
|
bool m_loop;
|
||||||
|
std::string m_animName;
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif /* defined(__SpineExample__CCSpineNode__) */
|
#endif /* defined(__SpineExample__CCSpineNode__) */
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user