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

前端之家收集整理的这篇文章主要介绍了我的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);
具体辐射性进度条已经解释。 原文链接:https://www.f2er.com/cocos2dx/342804.html

猜你在找的Cocos2d-x相关文章