您的位置:首页 > 其它

CCActionProgressTimer(进度条动作)

2014-05-21 17:41 176 查看
需要先看CCProgressTimer.h

#ifndef __ACTION_CCPROGRESS_TIMER_H__
#define __ACTION_CCPROGRESS_TIMER_H__

#include "CCActionInterval.h"

NS_CC_BEGIN
/**
@brief Progress to percentage
@since v0.99.1
*/
class CC_DLL CCProgressTo : public CCActionInterval
{
public:
/** Initializes with a duration and a percent */
bool initWithDuration(float duration, float fPercent); //动作时间,显示百分比

virtual CCObject* copyWithZone(CCZone *pZone);
virtual void startWithTarget(CCNode *pTarget);
///////

void CCProgressTo::startWithTarget(CCNode *pTarget)
{
CCActionInterval::startWithTarget(pTarget);
m_fFrom = ((kProgressTimerCast)(pTarget))->getPercentage();

// XXX: Is this correct ?
// Adding it to support CCRepeat
if (m_fFrom == 100)
{
m_fFrom = 0;
}
}
///////
virtual void update(float time);
//////

void CCProgressTo::update(float time)
{
((kProgressTimerCast)(m_pTarget))->setPercentage(m_fFrom + (m_fTo - m_fFrom) * time);
//#define kProgressTimerCast CCProgressTimer* // CCProgressTimer见CCProgressTimer.h
}

///////
public:
/** Creates and initializes with a duration and a percent */
static CCProgressTo* create(float duration, float fPercent);
protected:
float m_fTo;
float m_fFrom;
//默认 不可设置
};

/**
@brief Progress from a percentage to another percentage
@since v0.99.1
*/
class CC_DLL CCProgressFromTo : public CCActionInterval //可以设置from 和 to 百分比
{
public:
/** Initializes the action with a duration, a "from" percentage and a "to" percentage */
bool initWithDuration(float duration, float fFromPercentage, float fToPercentage);

virtual CCObject* copyWithZone(CCZone *pZone);
virtual CCActionInterval* reverse(void);
virtual void startWithTarget(CCNode *pTarget);
virtual void update(float time);

public:

/** Creates and initializes the action with a duration, a "from" percentage and a "to" percentage */
static CCProgressFromTo* create(float duration, float fFromPercentage, float fToPercentage);
protected:
float m_fTo;
float m_fFrom;
};

// end of actions group
/// @}

NS_CC_END

#endif // __ACTION_CCPROGRESS_TIMER_H__
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: 
相关文章推荐