CCActionProgressTimer(进度条动作)

本文详细解读了CCProgressTimer类的实现细节,并通过实例展示了如何使用该类实现进度条动画效果。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >


需要先看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__


评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值