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. 基于端口的VLAN典型配置指导

    本文为转发,简单明了,我喜欢 VLAN典型配置全过程如下: 组网图 图1-1 基于端口的VLAN组网示意图 应用要求 如图1-1所示,Switch A和Switch B分别连接了不同部门使用的Host ...

  2. IOS_Note

    关键字:可以搜索这些关键字找到具体内容 退回输入键盘.CGRect.CGPoint & CGSize.设置透明度.设置背景色.自定义颜色. 竖屏.横屏.状态栏高  (显示时间和网络状态). 导 ...

  3. IntelliJ IDEA 开发swing(二)

    原文:idea开发swing(二) 闲话少说,书接idea开发swing(一). 程序编译完成后,需要打包发布,如果有fat_jar的同学可以通过该插件打包,这里是使用ant来打包,步骤如下: 一.编 ...

  4. 基于visual Studio2013解决C语言竞赛题之0608水仙花函数

     题目 解决代码及点评 /* 功能:写一函数判断某数是否"水仙花数",所谓"水仙花数"是指一个三位数, 其各位数字立方和等于该数本身. */ #includ ...

  5. 基于visual Studio2013解决C语言竞赛题之0908文件合并

       题目

  6. 一步一步重写 CodeIgniter 框架 (4) —— load_class 管理多个对象实例的思路

    我们使用CodeIgniter 框架最主要是想利用其 MVC 特性,将模型.视图分开,并通过控制器进行统一控制.在尝试实现 MVC 模式之前,我们将实现其中一个对程序结构非常有用的技巧,就是 load ...

  7. Resist the Temptation of the Singleton Pattern

    Resist the Temptation of the Singleton Pattern Sam Saariste THE SiNGLETON PATTERN SOLVES MANY OF YOU ...

  8. Hough变换在opencv中的应用

    霍夫曼变换(Hough Transform)的原理 霍夫曼变换是一种可以检测出某种特殊形状的算法,OpenCV中用霍夫曼变换来检测出图像中的直线.椭圆和其他几何图形.由它改进的算法,可以用来检测任何形 ...

  9. 基于visual Studio2013解决面试题之1002公共子串

     题目

  10. Cocos2d-x教程第(11)讲-利用遮罩(蒙版)CCLayerColor制作新手引导界面(上)

    欢迎转载,转载时请注明原文出处:http://blog.csdn.net/u012945598/article/details/17280019 源码下载地址:http://download.csdn ...