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. BZOJ 1877: [SDOI2009]晨跑( 最小费用最大流 )

    裸的费用流...拆点, 流量限制为1, 最后的流量和费用即答案. ------------------------------------------------------------------- ...

  2. BZOJ 4145: [AMPPZ2014]The Prices( 状压dp + 01背包 )

    我自己只能想出O( n*3^m )的做法....肯定会T O( nm*2^m )做法: dp( x, s ) 表示考虑了前 x 个商店, 已买的东西的集合为s. 考虑转移 : 先假设我们到第x个商店去 ...

  3. redis 消息队列(发布订阅)、持久化(RDB、AOF)、集群(cluster)

    一:订阅: 192.168.10.205:6379> SUBSCRIBE test Reading messages... (press Ctrl-C to quit) 1) "sub ...

  4. Python中打印列表的序号和内容

    ==>the start 最近作业里要用到遍历打印出列表中的序号和内容,我刚开始用了个很笨的方法来写,后来老师说可以使用enumerate()函数,所以我就特意研究了下. 先看我之前用的笨方法: ...

  5. Jquery学习笔记:删除节点的操作

    假设如下的html代码 <div id="mydiv" style="width:100px;height:100px;border:1px solid red&q ...

  6. hibernate笔记(一)

    一.主配置文件hibernate.cfg.xml 位置:放在src目录下. 主要包含信息: 一.数据库信息    数据库方言(类的全名) 及 数据库链接信息 1.      数据库方言 2.      ...

  7. H3C HCSE 官方培训胶片(中文) 下载

    H3C HCSE 官方培训胶片(中文) 点击文件名下载 HM-040 OSPF路由协议(V5.1).ppt HM-041 BGP协议原理及配置(V5.0).ppt HM-041 BGP协议原理及配置( ...

  8. 浅谈初次搭建nginx+php+mysql遇到的问题

    先说明下我linux上的环境: nginx + php(5.5.10) + mysql 開始的源代码已经在本地写好,并调试成功(本地的环境是用XAMPP的默认配置).在把代码上传至linux上时,出现 ...

  9. APEC计划指引我们前进:云计算服务将上升

    APEC纲领指引我们前进:云计算服务业必将兴起 这是APEC领导人的合影: 这次APEC会议通过了<北京纲领>和<亚太伙伴关系声明>,进一步明白了亚太地区经济合作的发展方向.目 ...

  10. jsp 分页(数据库读取数据)

    <%@ page contentType="text/html; charset=gb2312"%> <%@ page language="java&q ...