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)
|
||||
|
||||
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)
|
||||
{
|
||||
@ -40,10 +56,6 @@ bool CCSpineNode::initWithFiles(const char* skeletonFileName, const char* atlasF
|
||||
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));
|
||||
@ -83,3 +99,20 @@ void CCSpineNode::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 {
|
||||
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__) */
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user