📄 cspriteanim.h
字号:
/*************************************************************************************
** 文件名: CSpriteAnim.h
** 描述: 用以控制精灵动画的基类,被具体的精灵类继承
** 具体信息见附带文档:CSpriteAnim类文档.doc
** 作者: Kevin Lynx
** 日期: 2006.8.13
**
**
** 上次更新:2006.8.16
** 2006.10.16:
** e_Dir, e_Action没有用到,反而使这个类不怎么通用--用户必须修改头文件加入自己的状态
** 于是去掉了e_Dir, e_Action。
**************************************************************************************/
#ifndef CSPRITE_ANIM_H
#define CSPRITE_ANIM_H
const int PLAY_FINISHED = -1; //播放完毕标志
//精灵状态结构
struct CSpriteStatus
{
int m_dir; //direction...
int m_action; //action...
int m_minFrame; //the min index in the sprite pic array
int m_maxFrame; //the max index in the sprite pic array
float m_curFrame; // m_minFrame <= m_curFrame <= m_maxFrame
float m_delay; //how long the curFrame will change...
// m_curFrame += (m_delay * time),usually 0.125..
int m_times; //播放次数,2006.8.16加入
//-1表示循环播放
int m_curTimes; //已经播放的次数
};
class CSpriteAnim
{
public :
CSpriteAnim();
virtual ~CSpriteAnim();
//初始化,指定精灵有多少个状态,并分配内存准备存储,必须调用
bool InitStatus( int statusCount );
//增加具体的状态信息,信息被添加到刚才分配的内存里
//statusIndex 通常从0-->statusCount - 1.
void AddStatus( int statusIndex, int dir, int action,
int minFrame, int maxFrame, float delay = 1.0f,
int times = -1 );
//设置精灵当前的状态
bool SetStatus( int dir, int action );
//得到精灵当前的状态
CSpriteStatus GetStatus();
//更新精灵动画帧,time为fps系统的SpeedFactor值
int UpdateAnimFrame( float time); //update the curFrame
int GetCurFrame() { return (int)m_statusPool[m_status].m_curFrame ; }
protected:
CSpriteStatus *m_statusPool; //point the address where stroes all status
int m_status; //current status for the sprite
int m_statusCount; //how many status there
};
#endif
//File end here.
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -