Cocos2d-x结构学习(十七)CCSkeletonAnimation、CCSkeleton、AnimationState、AnimationState、SkeletonData

1、CCSkeletonAnimation:继承自CCSkeleton,骨骼动画类

class CC_EX_DLL CCSkeletonAnimation: public CCSkeleton {
public:
	std::vector<AnimationState*> states;     //状态容器

	static CCSkeletonAnimation* createWithData (SkeletonData* skeletonData);           //相关创建函数
	static CCSkeletonAnimation* createWithFile (const char* skeletonDataFile,Atlas* atlas,float scale = 1);
	static CCSkeletonAnimation* createWithFile (const char* skeletonDataFile,const char* atlasFile,float scale = 1);

	CCSkeletonAnimation (SkeletonData* skeletonData);
	CCSkeletonAnimation (const char* skeletonDataFile,float scale = 1);
	CCSkeletonAnimation (const char* skeletonDataFile,float scale = 1);

	virtual ~CCSkeletonAnimation ();

	virtual void update (float deltaTime);

	void addAnimationState (AnimationStateData* stateData = 0);                                      //两个添加状态函数
	void setAnimationStateData (AnimationStateData* stateData,int stateIndex = 0);
	void setMix (const char* fromAnimation,const char* toAnimation,float duration,int stateIndex = 0);
	void setAnimation (const char* name,bool loop,int stateIndex = 0);                                 //设置动画
	void addAnimation (const char* name,float delay = 0,int stateIndex = 0);              //添加
	void clearAnimation (int stateIndex = 0);                                                    //清除

protected:
	CCSkeletonAnimation ();
private:
	typedef CCSkeleton super;
	std::vector<AnimationStateData*> stateDatas;
	void initialize ();
};
2、CCSkeleton:继承自CCNodeRGBA和CCBlendProtocol,骨骼处理类
class CC_EX_DLL CCSkeleton: public cocos2d::CCNodeRGBA,public cocos2d::CCBlendProtocol {
public:
	Skeleton* skeleton;
	Bone* rootBone;
	float timeScale;
	bool debugSlots;
	bool debugBones;
	bool premultipliedAlpha;

	static CCSkeleton* createWithData (SkeletonData* skeletonData,bool ownsSkeletonData = false);
	static CCSkeleton* createWithFile (const char* skeletonDataFile,float scale = 1);
	static CCSkeleton* createWithFile (const char* skeletonDataFile,float scale = 1);

	CCSkeleton (SkeletonData* skeletonData,bool ownsSkeletonData = false);
	CCSkeleton (const char* skeletonDataFile,float scale = 1);
	CCSkeleton (const char* skeletonDataFile,float scale = 1);

	virtual ~CCSkeleton ();

	virtual void update (float deltaTime);                 //更新
	virtual void draw ();                               //绘制
	virtual cocos2d::CCRect boundingBox ();               //获得包围体

	void updateWorldTransform ();                           //更新世界变换

	void setToSetupPose ();
	void setBonesToSetupPose ();
	void setSlotsToSetupPose ();

	Bone* findBone (const char* boneName) const;            //查找骨骼
	Slot* findSlot (const char* slotName) const;

	bool setSkin (const char* skinName);                      //设置皮肤
	
	Attachment* getAttachment (const char* slotName,const char* attachmentName) const;
	bool setAttachment (const char* slotName,const char* attachmentName);

	CC_PROPERTY(cocos2d::ccBlendFunc,blendFunc,BlendFunc);
	virtual void setOpacityModifyRGB (bool value);
	virtual bool isOpacityModifyRGB ();
protected:
	CCSkeleton ();
	void setSkeletonData (SkeletonData* skeletonData,bool ownsSkeletonData);
	cocos2d::CCTextureAtlas* getTextureAtlas (RegionAttachment* regionAttachment) const;
private:
	bool ownsSkeletonData;
	Atlas* atlas;
	void initialize ();
};
3、AnimationState:动画状态结构体
typedef struct {
	AnimationStateData* const data;
	Animation* const animation;
	float time;
	int/*bool*/loop;
} AnimationState;
4、AnimationStateData:动画数据结构体
typedef struct {
	SkeletonData* const skeletonData;
	const void* const entries;
} AnimationStateData;
5、SkeletonData:骨骼数据结构体
typedef struct {
	int boneCount;
	BoneData** bones;

	int slotCount;
	SlotData** slots;

	int skinCount;
	Skin** skins;
	Skin* defaultSkin;

	int animationCount;
	Animation** animations;
} SkeletonData;

相关文章

操作步骤 1、创建cocos2d-x工程 2、新建 Scene1.cpp Scene1.h Scene1.h代码 #ifndef __SCENE1_H__#defi...
开发环境:OS(WINDOWS 8.1 X64 企业版) cocos2d-x 2.2.1 vs2010 想给vs安装上cocos的模版,执行Install...
把创建项目做成一个批处理,当创建项目时可以省时省力很多。 操作步骤 1、在 E:cocos2d-x-2.2.1toolspr...
https://www.cnblogs.com/JiaoQing/p/3906780.html 四个响应函数 1 EventListenerPhysicsContact* evC...
转载于 http://www.cnblogs.com/kenkofox/p/3926797.html 熟悉js的dom事件或者flash事件的,基本都能立...
ScrollView(滚动容器)加载大量item时会导致游戏界面的卡顿,严重时整个界面会出现卡死的情况。最近项...