Cocos2d-x CCProgressTimer
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的更多相关文章
- CCProgressTo 和CCProgressTimer
在cocos2d中相同提供了非常多表现图片和精灵的方式,上一篇其中提到的切换场景的方式之中的一个是顺或逆时针切入的方法,在图片上也能够使用,test里有一个样例介绍CCProgressTimer能够实 ...
- CCProgressTo和CCProgressTimer
在cocos2d中同样提供了很多表现图片和精灵的方式,上一篇当中提到的切换场景的方式之一是顺或逆时针切入的方法,在图片上也可以使用,test里有一个例子介绍CCProgressTimer可以实现一些图 ...
- 小尝试一下 cocos2d
好奇 cocos2d 到底是怎样一个框架,正好有个项目需要一个游戏框架,所以稍微了解了一下.小结一下了解到的情况. 基本概念 首先呢,因为 cocos2d 是基于 pyglet 做的,你完全可以直接用 ...
- 采用cocos2d-x lua 制作数字滚动效果样例
require "Cocos2d"require "Cocos2dConstants"local testscene = class("testsce ...
- Cocos2d 利用继承Draw方法制作可显示三维数据(宠物三维等)的三角形显示面板
很久没有写博客了,这段时间比较忙,又是搬家又是做自己的项目,还有太多琐碎的事情缠身,好不容易抽出时间把最近自己做的一些简单例子记录一下. 在我的项目中,我需要一个显示面板来显示游戏中的一个三维数据,例 ...
- iPhone开发与cocos2d 经验谈
转CSDN jilongliang : 首先,对于一个完全没有mac开发经验,甚至从没摸过苹果系统的开发人员来说,首先就是要熟悉apple的那一套开发框架(含开发环境IDE.开发框架uikit,还有开 ...
- cocos2d学习记录
视频 - http://www.manew.com/forum-105-3.html一个论坛帖 - http://www.zhihu.com/question/21114802官网 - http:// ...
- Android下Cocos2d创建HelloWorld工程
最近在搭建Cocos2d的环境,结果各种问题,两人弄了一天才能搞好一个环境-! -_-!! 避免大家也可能会遇到我这种情况,所以写一个随笔,让大家也了解下如何搭建吧- 1.环境安装准备 下载 tadp ...
- 学生信息管理系统(cocos2d引擎)——数据结构课程设计
老师手把手教了两天半,看了一下模式,加了几个功能就大功告成了!!! 给我的感想就是全都是指针! 添加图片精灵: CCSprite* spBG = CCSprite::create("&qu ...
- cocos2d触碰例子代码
// // TestLayer.h // MiniTD // // Created by OnePiece on 12-7-30. // Copyright 2012年 __MyCompanyName ...
随机推荐
- 纠错记录(Could not open the editor: Android XML Editor cannot process this input.)
Eclipse无法打开xml文件 preference->general->edit->file association->file types->选择.xml,然后在a ...
- Android:创建文件或文件夹以及获取sd卡根目录
目录结构: 功能,可以根据录入的目录或者文件夹生成相应的文件或者文件夹 首先需要添加一个权限: <uses-permission android:name="android.permi ...
- C 语言学习 之搭建环境和熟悉命令
Open Terminal 打开终端To run a command as administrator (user "root"), use "sudo <comm ...
- 16-UIKit(AutoLayout、Animation)
目录: 一.AutoLayout自动布局 二.动画(Animation) 回到顶部 一.AutoLayout自动布局 1.什么是AutoLayout 从ios6开始引入的新技术,是新版的自动布局技术 ...
- android handler looper thread
在线程中调用包含创建handler方法的时候,会报错,提示: “need call Looper.prepare()” -- 在创建之前,调用Looper.prepare()方法来创建一个looper ...
- Spring源代码解析 ---- 循环依赖
一.循环引用: 1. 定义: 循环依赖就是循环引用,就是两个或多个Bean相互之间的持有对方,比方CircularityA引用CircularityB,CircularityB引用Circularit ...
- Cocos2dx3.1 获取当前系统时间
以下是获代替码 原文地址:http://blog.csdn.net/qqmcy/article/details/28233565 // // Tools.h // // // Created by 杜 ...
- 最简单的基于FFMPEG+SDL的视频播放器 ver2 (採用SDL2.0)
===================================================== 最简单的基于FFmpeg的视频播放器系列文章列表: 100行代码实现最简单的基于FFMPEG ...
- MSSQL - 根据时间倒序删除第一行数据
delete top(1) from Tb_PaintOut where PaintNumber = (select top (1) PaintNumber from Tb_PaintOut orde ...
- Delphi 10.1说明
发布说明:http://docwiki.embarcadero.com/RADStudio/Berlin/en/Main_Page更新说明:http://docwiki.embarcadero.com ...