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

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

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

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

typedef enum {
/// Radial Counter-Clockwise
kCCProgressTimerTypeRadial,
/// Bar
kCCProgressTimerTypeBar,
} CCProgressTimerType;

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

CCSize wSize = CCDirector::sharedDirector()->getWinSize();
progressTimer = CCProgressTimer::create(CCSprite::create("progress.gif"));
progressTimer->setType(kCCProgressTimerTypeRadial);
// 默认的情况下,环形渐变的方向是:顺时针
// 改变其渐变的方向 Makes the ridial CCW (逆时针)
progressTimer->setReverseProgress(true);
progressTimer->setPosition(wSize.width/2,wSize.height/2);
this->addChild(progressTimer);

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

渐变的方向问题:

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

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

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

首先是setMidpoint设置起点

/**
* 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)
*/

其次是setBarChangeRate设置变化rate

/**
* 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);
*/

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

CCSize wSize = CCDirector::sharedDirector()->getWinSize();
progressTimer = CCProgressTimer::create(CCSprite::create("progress.gif"));
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)); //从下到上
// progressTimer->setMidpoint(ccp(0.5, 0));
// progressTimer->setBarChangeRate(ccp(0, 1)); progressTimer->setPosition(wSize.width/2,wSize.height/2);
this->addChild(progressTimer);

(4) 执行变化

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

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

前者:Progress to percentage(初始化有两个参数)(float duration, float fPercent)

后者:Progress from a percentage to another percentage(初始化有三个参数)(float duration, float fFromPercentage, float fToPercentage)

CCProgressTo *progressTo = CCProgressTo::create(2.0, 100);
//等价于:
//CCProgressFromTo *progressFromTo = CCProgressFromTo::create(2.0, 0, 100);
progressTimer->runAction(CCRepeatForever::create(progressTo));

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

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

this->scheduleUpdate();
void HelloWorld::update(float dt)
{
float percentage = progressTimer->getPercentage(); if (percentage < 100) {
percentage += 1;
progressTimer->setPercentage(percentage);
}
}

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

Cocos2d-x CCProgressTimer的更多相关文章

  1. CCProgressTo 和CCProgressTimer

    在cocos2d中相同提供了非常多表现图片和精灵的方式,上一篇其中提到的切换场景的方式之中的一个是顺或逆时针切入的方法,在图片上也能够使用,test里有一个样例介绍CCProgressTimer能够实 ...

  2. CCProgressTo和CCProgressTimer

    在cocos2d中同样提供了很多表现图片和精灵的方式,上一篇当中提到的切换场景的方式之一是顺或逆时针切入的方法,在图片上也可以使用,test里有一个例子介绍CCProgressTimer可以实现一些图 ...

  3. 小尝试一下 cocos2d

    好奇 cocos2d 到底是怎样一个框架,正好有个项目需要一个游戏框架,所以稍微了解了一下.小结一下了解到的情况. 基本概念 首先呢,因为 cocos2d 是基于 pyglet 做的,你完全可以直接用 ...

  4. 采用cocos2d-x lua 制作数字滚动效果样例

    require "Cocos2d"require "Cocos2dConstants"local testscene = class("testsce ...

  5. Cocos2d 利用继承Draw方法制作可显示三维数据(宠物三维等)的三角形显示面板

    很久没有写博客了,这段时间比较忙,又是搬家又是做自己的项目,还有太多琐碎的事情缠身,好不容易抽出时间把最近自己做的一些简单例子记录一下. 在我的项目中,我需要一个显示面板来显示游戏中的一个三维数据,例 ...

  6. iPhone开发与cocos2d 经验谈

    转CSDN jilongliang : 首先,对于一个完全没有mac开发经验,甚至从没摸过苹果系统的开发人员来说,首先就是要熟悉apple的那一套开发框架(含开发环境IDE.开发框架uikit,还有开 ...

  7. cocos2d学习记录

    视频 - http://www.manew.com/forum-105-3.html一个论坛帖 - http://www.zhihu.com/question/21114802官网 - http:// ...

  8. Android下Cocos2d创建HelloWorld工程

    最近在搭建Cocos2d的环境,结果各种问题,两人弄了一天才能搞好一个环境-! -_-!! 避免大家也可能会遇到我这种情况,所以写一个随笔,让大家也了解下如何搭建吧- 1.环境安装准备 下载 tadp ...

  9. 学生信息管理系统(cocos2d引擎)——数据结构课程设计

    老师手把手教了两天半,看了一下模式,加了几个功能就大功告成了!!! 给我的感想就是全都是指针! 添加图片精灵: CCSprite*  spBG = CCSprite::create("&qu ...

  10. cocos2d触碰例子代码

    // // TestLayer.h // MiniTD // // Created by OnePiece on 12-7-30. // Copyright 2012年 __MyCompanyName ...

随机推荐

  1. Sql 参数的使用

    代码片段: a)声明实例 1.声明SQLCommand实例. SqlCommand cmd = new SqlCommand(); 2.声明SqlDataAdapter实例. SqlDataAdapt ...

  2. Smarty模板Windows下写代码 放到CentOS6.5无法正确解析

    如题:报错: Unable to load template file 'System/header.htm' in '/var/www/website/cms/Template/Default/We ...

  3. 12-UIKit(View绘制、绘制曲线、绘制文字、贴图)

    目录: 1. View绘制 2. 绘制曲线 3. 绘制文字 4. 贴图 回到顶部 1. View绘制 1.1 做出自己的视图对象 TRCell : UITableViewCell : UIView U ...

  4. VS2010 安装 Boost 库 1.54

    Boost库被称为C++准标准库, 功能很是强大, 下面记录我在VS2010中安装使用Boost库的过程. 首先上官网http://www.boost.org/下载最新的Boost库, 我的版本是1_ ...

  5. Swift - 使用HTML5进行iOS开发(将HTML5打包成iOS应用)

    最近越来越流行使用HTML5进行跨平台应用开发,先不说运行效率如何.从人力成本来说,只要写一套html页面就可以打包发布到安卓和iOS等多个平台,确实会省下不少时间和人力(这个领导最喜欢了). 下面简 ...

  6. Hadoop源代码导入Eclipse

    须要进一步学习hadoop.须要看看内部源代码实现.因此须要将hadoop源代码导入都eclipse中,简单总结一下,详细过程例如以下: 首先确保已经安装了git.maven3.protobuf2.5 ...

  7. 基于visual Studio2013解决面试题之0901奇偶站队

     题目

  8. SqlParameter参数化查询

    上篇博客写了关于重构代码用到的SQLHelper类,这个类包括四种函数,根据是否含参和是否有返回值各分两种.在这里写写传参过程用到的SqlParameter. 如果我们使用如下拼接sql字符串的方式进 ...

  9. Response.AppendCookie

    //写入 protected void Button2_Click(object sender, EventArgs e) { HttpCookie cookie=new HttpCookie(&qu ...

  10. UVA 2039 Pets(网络流)

    Problem Description Are you interested in pets? There is a very famous pets shop in the center of th ...