我的Cocos2d-x学习笔记(十七)CCProgressTo

Cocos2d-x提供了进度条动作,该类继承CCActionInterval。继承关系如下:


在使用CCProgressTo时还需要CCProgressTimer。

在CCProgressTimer类中,仅仅只有一个create函数用来创建,其参数是一个精灵,如下:

static CCProgressTimer* create(CCSprite* sp);

CCProgressTimer在创建后,还需要设置一些其他参数。

CCProgressTo类中也仅仅有一个create用来创建,代码如下:

    /** Creates and initializes with a duration and a percent */
    static CCProgressTo* create(float duration, float fPercent);
float duration:进度条执行完需要的时间。

float fPercent:进度条的百分比,100是进度条满。

一、辐射性进度条

实例:

	CCProgressTo* radial = CCProgressTo::create(2, 100);
	CCProgressTimer* radialProgress = CCProgressTimer::create(CCSprite::create("btn_go_0.png"));
	radialProgress->setType(kCCProgressTimerTypeRadial);
	radialProgress->setPosition(ccp(100,100));

	radialProgress->setMidpoint(ccp(0.1,0.2));
	radialProgress->setReverseProgress(true);

	radialProgress->runAction(radial);

	addChild(radialProgress);

setType:用来设置进度条的类型。

setMidpoint:用来设置旋转中心。

setReverseProgress:用来设置进度条执行方向,默认是顺时针。

Midpoint与BarChangeRate声明如下:

    /**
     *    Midpoint is used to modify the progress start position.
     *    If you're using radials type then the midpoint changes the center point
     *    If you're using bar type the the midpoint changes the bar growth
     *        it expands from the center but clamps to the sprites edge so:
     *        you want a left to right then set the midpoint all the way to ccp(0,y)
     *        you want a right to left then set the midpoint all the way to ccp(1,y)
     *        you want a bottom to top then set the midpoint all the way to ccp(x,0)
     *        you want a top to bottom then set the midpoint all the way to ccp(x,1)
     */
    CC_PROPERTY(CCPoint, m_tMidpoint, Midpoint);

    /**
     *    This allows the bar type to move the component at a specific rate
     *    Set the component to 0 to make sure it stays at 100%.
     *    For example you want a left to right bar but not have the height stay 100%
     *    Set the rate to be ccp(0,1); and set the midpoint to = ccp(0,.5f);
     */
    CC_SYNTHESIZE(CCPoint, m_tBarChangeRate, BarChangeRate);
二、条状进度条

实例:

	CCProgressTimer * barProgress = CCProgressTimer::create(CCSprite::create("btn_go_0.png"));
	CCProgressTo * bar = CCProgressTo::create(2, 100);
	barProgress->setType(kCCProgressTimerTypeBar);
	barProgress->setMidpoint(ccp(1,0));
	barProgress->setBarChangeRate(ccp(1,1));
	
	barProgress->setPosition(ccp(200, 100));
	barProgress->runAction(bar);
	addChild(barProgress);
具体辐射性进度条已经解释。

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值