微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

我的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.jb51.cc/cocos2dx/342804.html

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。

相关推荐