加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 百科 > 正文

寒風的Cocos之旅C++篇之进度条的使用

发布时间:2020-12-14 16:35:27 所属栏目:百科 来源:网络整理
导读:首先进度条的作用在游戏中充当着重要的角色。如:人物的血条、计时的时间条、小怪的血量等,它以一种直观的形态呈现在我们的视野当中,话不多说,直接上货了。 strongspan style="font-family:FangSong_GB2312;" //进度条背景 Sprite *progressbgSprite; pro

首先进度条的作用在游戏中充当着重要的角色。如:人物的血条、计时的时间条、小怪的血量等,它以一种直观的形态呈现在我们的视野当中,话不多说,直接上货了。

<strong><span style="font-family:FangSong_GB2312;">   
    //进度条背景
    Sprite *progressbgSprite;
    progressbgSprite = Sprite::create("bonusbar.png") ;
    //progressbgSprite->setAnchorPoint(ccp(0,0));//修改定点对应点
    progressbgSprite->setPosition(Vec2(size.width/2,size.height/3-140));
    this->addChild(progressbgSprite,3);
    progressbgSprite->setVisible(true);
    //进度条正面
    Sprite *progressSprite = Sprite::create("bonusbar_fill.png");
    progress = ProgressTimer::create(progressSprite);
    //创建进度条.
    //progress->setAnchorPoint(ccp(0,0));
    progress->setType(kCCProgressTimerTypeBar);  //中间为从左向右的进度条,类型为水平
    progress->setPosition(Vec2(size.width/2,size.height/3-140));
    //进度动画运动方向
    progress->setMidpoint(ccp(0,0));
    //进度条宽高变化
    progress->setBarChangeRate(ccp(1,0)); //设置进度条为从左向右随进度增长而显现
    progress->setPercentage(100.0f);//值
    this->addChild(progress,3);
    progress->setVisible(true);
    </span></strong>


进度条分为2个。一个是背景进度条,一个是会动的进度条。步骤如下:

①定义一个进度条的背景

②将会动的进度条,通过背景进度条create

③将会动的背景进度条通过ProgressTimer来create

④设定进度条的运动方向setMidpoint(ccp(0,0)) //(0,1)是竖直方向

⑤进度条的高的变化,设置它的百分比(setPercentage)

⑥完成进度条,配合Update函数来实现运动。

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读