Cocos2d-x CCProgressTimer

Cocos2d-x CCProgressTimer,第1张

概述Cocos2d-x CCProgressTimer CCProgressTimer,创建使用这个节点可以大致实现两个作用的效果: 其一:在游戏中几乎大部分的游戏启动界面都是游戏加载画面,那么用到的一般是进度条提示加载进度,其使用的就是CCProgressTimer。 其二:在游戏中需要对精灵的出现等动作制作一些渐显的效果。   (1)类型一般就是两种:   typedef enum {       Cocos2d-x CCProgressTimer

CCProgresstimer,创建使用这个节点可以大致实现两个作用的效果:

其一:在游戏中几乎大部分的游戏启动界面都是游戏加载画面,那么用到的一般是进度条提示加载进度,其使用的就是CCProgresstimer。

其二:在游戏中需要对精灵的出现等动作制作一些渐显的效果。

(1)类型一般就是两种:

typedefenum{ ///RadialCounter-Clockwise kCCProgresstimerTypeRadial, ///bar kCCProgresstimerTypebar,0); background-color:inherit">}CCProgresstimerType;


(2)类型1:radial(环形)

CCSizewSize=CCDirector::sharedDirector()->getWinSize(); progresstimer=CCProgresstimer::create(CCSprite::create("progress.gif")); progresstimer->setType(kCCProgresstimerTypeRadial); //默认的情况下,环形渐变的方向是:顺时针 //改变其渐变的方向MakestherIDialccw(逆时针) progresstimer->setReverseProgress(true); progresstimer->setposition(wSize.wIDth/2,wSize.height/2); this->addChild(progresstimer);


(3)类型2:bar (条形:包括vertical 和 horizontal)

渐变的方向问题:

vertical竖直方法包括从上到下和从下到上;

horizontal水平方向包括从左到右和从右到左。

这里涉及到两个设置参数:

首先是setMIDpoint设置起点

/** *MIDpointisusedtomodifytheprogressstartposition. *Ifyou'reusingradialstypethenthemIDpointchangesthecenterpoint *Ifyou'reusingbartypethethemIDpointchangesthebargrowth *itexpandsfromthecenterbutclampstotheSpritesedgeso: *youwantalefttorightthensetthemIDpointallthewaytoccp(0,y) *youwantarighttoleftthensetthemIDpointallthewaytoccp(1,y) *youwantabottomtotopthensetthemIDpointallthewaytoccp(x,0) *youwantatoptobottomthensetthemIDpointallthewaytoccp(x,1) */


其次是setbarChangeRate设置变化rate

*Thisallowsthebartypetomovethecomponentataspecificrate *Setthecomponentto0tomakesureitstaysat100%. *Forexampleyouwantalefttorightbarbutnothavetheheightstay100% *Settheratetobeccp(0,1);andsetthemIDpointto=ccp(0,.5f); */


如果不用变化的方向,则设置该方向为0,否则设置为1。

progresstimer->setType(kCCProgresstimerTypebar); //从左到右 progresstimer->setMIDpoint(ccp(0,0.5)); progresstimer->setbarChangeRate(ccp(1,0)); //从右到左 //progresstimer->setMIDpoint(ccp(1,0.5)); //progresstimer->setbarChangeRate(ccp(1,0)); //从上到下 //progresstimer->setMIDpoint(ccp(0.5,1)); //progresstimer->setbarChangeRate(ccp(0,1)); //从下到上 this->addChild(progresstimer);


(4) 执行变化

①、如果是要实现精灵渐变的显示效果:

创建CCProgressto或者是CCProgressFromTo动作,让CCProgresstimer执行。
CCProgressto和CCProgressFromTo的区别是:

前者:Progress to percentage(初始化有两个参数)(floatduration,floatfPercent)

后者:Progress from a percentage to another percentage(初始化有三个参数)(floatduration,floatfFromPercentage,floatftopercentage)

CCProgressto*progressto=CCProgressto::create(2.0,100); //等价于: //CCProgressFromTo*progressFromTo=CCProgressFromTo::create(2.0,100); progresstimer->runAction(CCRepeatForever::create(progressto));


②、如果是要实现加载进度条的效果:

需要重载update方法,在这个方法中实现进度条percentage的变化。

this->scheduleUpdate();

voIDHelloWorld::update(floatdt) { floatpercentage=progresstimer->getPercentage(); if(percentage<100){ percentage+=1; progresstimer->setPercentage(percentage); } }

关于CCProgresstimer的更加详细的使用 demo可以参看引擎中sample中的ActionProgresstest。

总结

以上是内存溢出为你收集整理的Cocos2d-x CCProgressTimer全部内容,希望文章能够帮你解决Cocos2d-x CCProgressTimer所遇到的程序开发问题。

如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。

欢迎分享,转载请注明来源:内存溢出

原文地址: http://outofmemory.cn/web/1059604.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2022-05-25
下一篇 2022-05-25

发表评论

登录后才能评论

评论列表(0条)

保存