个人原创,欢迎转载:http://blog.csdn.net/dawn_moon/article/details/11478885

这个资源加载的loading界面demo是在玩客网做逆转三国的时候随手写的,虽然我在那只待了2个礼拜,但是也算参与了一个商业游戏项目了,学到不少东西。当时使用的cocos2d-x还是1.0版的,我用2.1.2的调试过了。

上图:

好了,很简单,代码有注释

上代码:

#include "HelloWorldScene.h"
#include "SimpleAudioEngine.h" using namespace cocos2d;
using namespace CocosDenshion; CCScene* HelloWorld::scene()
{
// 'scene' is an autorelease object
CCScene *scene = CCScene::create(); // 'layer' is an autorelease object
HelloWorld *layer = HelloWorld::create(); // add layer as a child to scene
scene->addChild(layer); // return the scene
return scene;
} // on "init" you need to initialize your instance
bool HelloWorld::init()
{
//////////////////////////////
// 1. super init first
if ( !CCLayer::init() )
{
return false;
} m_iLoadIdex = 0; /////////////////////////////
// 2. add a menu item with "X" image, which is clicked to quit the program
// you may modify it. // add a "close" icon to exit the progress. it's an autorelease object
CCMenuItemImage *pCloseItem = CCMenuItemImage::create(
"CloseNormal.png",
"CloseSelected.png",
this,
menu_selector(HelloWorld::menuCloseCallback) );
pCloseItem->setPosition( ccp(CCDirector::sharedDirector()->getWinSize().width - 20, 20) ); // create menu, it's an autorelease object
CCMenu* pMenu = CCMenu::create(pCloseItem, NULL);
pMenu->setPosition( CCPointZero );
this->addChild(pMenu, 1); /////////////////////////////
// 3. add your codes below... // add a label shows "Hello World"
// create and initialize a label
CCLabelTTF* pLabel = CCLabelTTF::create("Hello World", "Thonburi", 34); // ask director the window size
CCSize size = CCDirector::sharedDirector()->getWinSize(); // position the label on the center of the screen
pLabel->setPosition( ccp(size.width / 2, size.height - 20) ); // add the label as a child to this layer
this->addChild(pLabel, 1); // add "HelloWorld" splash screen"
CCSprite* pSprite = CCSprite::create("HelloWorld.png"); // position the sprite on the center of the screen
pSprite->setPosition( ccp(size.width/2, size.height/2) ); // add the sprite as a child to this layer
this->addChild(pSprite, 0); // loading边框
m_progressFrame = CCSprite::create("loading_fr.png");
addChild(m_progressFrame,1);
m_progressFrame->setPosition(ccp(240, 50)); // loading的动作条
m_progressBar = CCProgressTimer::create(CCSprite::create("loading_bar.png"));
m_progressBar->setType(kCCProgressTimerTypeBar);
addChild(m_progressBar);
m_progressBar->setVisible(true);
m_progressBar->setPosition(ccp(241, 51));
// 进度动画运动方向,从左到右
m_progressBar->setMidpoint(ccp(0, 0));
// 宽高变化,这里是宽度变化
m_progressBar->setBarChangeRate(ccp(1, 0));
m_progressBar->setPercentage(0); // loading动画,没有逻辑处理,实际情况则注释掉
CCProgressTo *to = CCProgressTo::create(10, 100);
m_progressBar->runAction(to); // 实际的loading逻辑,可以在这里加入
// scheduleUpdate();
return true;
} void HelloWorld::update(float dt)
{ m_iLoadIdex++; if (m_iLoadIdex <= 50) {
loadResource(m_iLoadIdex);
m_progressBar->setPercentage(m_iLoadIdex * 100.0 / 50);
} if (m_iLoadIdex >=50) {
unscheduleUpdate();
}
} // 实际的loading逻辑,加载资源可以在这里添加。
// 这里只用了sleep来模拟
void HelloWorld::loadResource(int index)
{
CCLog("loading ....");
switch (index) {
case 0:
break;
default:
sleep(1.0);
break;
}
} void HelloWorld::menuCloseCallback(CCObject* pSender)
{
CCDirector::sharedDirector()->end(); #if (CC_TARGET_PLATFORM == CC_PLATFORM_IOS)
exit(0);
#endif
}

东西太简单,还需要上传demo源码么。要的留言

cocos2d-x游戏开发(十五)游戏加载动画loading界面的更多相关文章

  1. cocos2d-x游戏开发(十五)游戏载入动画loading界面

    这个资源载入的loading界面demo是在玩客网做逆转三国的时候随手写的,尽管我在那仅仅待了2个礼拜.可是也算參与了一个商业游戏项目了,学到不少东西.当时使用的cocos2d-x还是1.0版的,我用 ...

  2. WebGL简易教程(十五):加载gltf模型

    目录 1. 概述 2. 实例 2.1. 数据 2.2. 程序 2.2.1. 文件读取 2.2.2. glTF格式解析 2.2.3. 初始化顶点缓冲区 2.2.4. 其他 3. 结果 4. 参考 5. ...

  3. Ionic Js十九:加载动画

    ion-spinner ionSpinner 提供了许多种旋转加载的动画图标.当你的界面加载时,你就可以呈现给用户相应的加载图标. 该图标采用的是SVG.  实例 HTML 代码 <ion-c ...

  4. 【读书笔记《Android游戏编程之从零开始》】19.游戏开发基础(游戏音乐与音效)

    在一款游戏中,除了华丽的界面 UI 直接吸引玩家外,另外重要的就是游戏的背景音乐与音效:合适的背景音乐以及精彩的音效搭配会令整个游戏上升一个档次. 在 Android 中.常用于播放游戏背景音乐的类是 ...

  5. Unity 4.2.0 官方最新破解版(Unity3D 最新破解版,3D游戏开发工具和游戏引擎套件)

    Unity是一款跨平台的游戏开发工具,从一开始就被设计成易于使用的产品.作为一个完全集成的专业级应用,Unity还包含了价值数百万美元的功能强大的游戏引擎.Unity作为一个游戏开发工具,它的设计主旨 ...

  6. Unity 2D游戏开发教程之游戏中精灵的跳跃状态

    Unity 2D游戏开发教程之游戏中精灵的跳跃状态 精灵的跳跃状态 为了让游戏中的精灵有更大的活动范围,上一节为游戏场景添加了多个地面,于是精灵可以从高的地面移动到低的地面处,如图2-14所示.但是却 ...

  7. iOS帅气加载动画、通知视图、红包助手、引导页、导航栏、朋友圈、小游戏等效果源码

    iOS精选源码 如丝般顺滑的微信朋友圈(点赞,评论,图文混排表情,... 动态菜单第三版本:动态项,自适应方向 仿appstore首页滚动效果 iOS 透明导航栏方案 TransparentNavig ...

  8. (转)Unity3D游戏开发 NGUI之渐变加载到100%的Loading场景进度条

    NGUI 现有的进度条存在的问题: 进度条跳跃式前进,加载到90%后卡住,突然进入下一个场景.接下来就是解决这个问题. 背景 通常游戏的主场景包含的资源较多,这会导致加载场景的时间较长.为了避免这个问 ...

  9. 微信小游戏 4M升8M分包加载

    一.微信分包加载 微信分包加载教程 嘛,因为原来的4M太小了,满足不了小游戏内容的需求,现在提升到了8M.这8M可以分包加载,而不需要一次性加载8M. 如果是老版本,则分包加载不起作用,会一次加载8M ...

随机推荐

  1. 玩转Linux网络namespace-单机自环測试与策略路由

    上周有厂商到公司測试,拿了一块据说非常猛的网络处理加速PCIe板卡,拎在手里沉甸甸的非常有分量,最让人意淫的是那4个万兆光口,于是我迫不及待的想要一览光口转发时那种看不见的震撼. 可是,仅凭4个光口怎 ...

  2. 多线程wait()和sleep()以及InterruptedException异常

    1.核心区别: sleep用于线程控制,wait用于线程间的通信. sleep是Thread类的方法,是让线程休息一段时间,然后自动恢复运行,与其他线程无关,与同步无关,也与锁无关(拿锁时不会释放锁) ...

  3. 随机生成器、thread(暂停)、清屏定义

    1.生成一个随机生成器 Random a = new Random(); //()可以填写随机生成器的种子,这个种子只能是整数(int) ); //()内的数字代表小于5的非负整数,包括零,例如0,1 ...

  4. 已经上架的app(可供销售)在AppStore上搜不到的解决办法

    这两天很是头大, 因为3天前手动发布的app到现在都还没在AppStore上看到,打了无数电话给苹果和发邮件给review团队. 下面说说怎么解决我们在iTunes后台看到是绿灯(可供销售)但是就是在 ...

  5. dpkg卸载和安装deb

    今天在linux mint上安装个东西,没有安装完全,但是启动的时候能够启动,为了防止以后出现异常,想把它卸载了,在软件上点卸载,没有反应, 如下图: 没有指定卸载的包源,无奈使用sudo apt-g ...

  6. C#学习之在辅助线程中修改UI控件----invoke方法

    Invoke and BeginInvoke 转载地址:http://www.cnblogs.com/worldreason/archive/2008/06/09/1216127.html 在Invo ...

  7. BZOJ 1858: [Scoi2010]序列操作( 线段树 )

    略恶心的线段树...不过只要弄清楚了AC应该不难.... ---------------------------------------------------------------- #inclu ...

  8. iOS 开发设计常用软件及工具整理

    1, xCode 2, AppCode 3, Skech 原型设计软件 4, Hype 动画设计工具 5, fontawsome 免费图表 6, Prepo icon, images.catlog 生 ...

  9. 在CentOS/RHEL/Scientific Linux 6下安装 LAMP

    LAMP 是服务器系统中开源软件的一个完美组合.它是 Linux .Apache HTTP 服务器.MySQL 数据库.PHP(或者 Perl.Python)的第一个字母的缩写代码.对于很多系统管理员 ...

  10. ORACLE存储过程笔记3

    ORACLE存储过程笔记3 流程控制 1.条件   if expression thenpl/sql or sqlend if;   if expression thenpl/sql or sqlel ...