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

上图:

好了,非常easy,代码有凝视

上代码:

  1. #include "HelloWorldScene.h"  
  2. #include "SimpleAudioEngine.h"  
  3.   
  4. using namespace cocos2d;  
  5. using namespace CocosDenshion;  
  6.   
  7. CCScene* HelloWorld::scene()  
  8. {  
  9.     // 'scene' is an autorelease object  
  10.     CCScene *scene = CCScene::create();  
  11.       
  12.     // 'layer' is an autorelease object  
  13.     HelloWorld *layer = HelloWorld::create();  
  14.   
  15.     // add layer as a child to scene  
  16.     scene->addChild(layer);  
  17.   
  18.     // return the scene  
  19.     return scene;  
  20. }  
  21.   
  22. // on "init" you need to initialize your instance  
  23. bool HelloWorld::init()  
  24. {  
  25.     //////////////////////////////  
  26.     // 1. super init first  
  27.     if ( !CCLayer::init() )  
  28.     {  
  29.         return false;  
  30.     }  
  31.       
  32.     m_iLoadIdex = 0;  
  33.   
  34.     /////////////////////////////  
  35.     // 2. add a menu item with "X" image, which is clicked to quit the program  
  36.     //    you may modify it.  
  37.   
  38.     // add a "close" icon to exit the progress. it's an autorelease object  
  39.     CCMenuItemImage *pCloseItem = CCMenuItemImage::create(  
  40.                                         "CloseNormal.png",  
  41.                                         "CloseSelected.png",  
  42.                                         this,  
  43.                                         menu_selector(HelloWorld::menuCloseCallback) );  
  44.     pCloseItem->setPosition( ccp(CCDirector::sharedDirector()->getWinSize().width - 20, 20) );  
  45.   
  46.     // create menu, it's an autorelease object  
  47.     CCMenu* pMenu = CCMenu::create(pCloseItem, NULL);  
  48.     pMenu->setPosition( CCPointZero );  
  49.     this->addChild(pMenu, 1);  
  50.   
  51.     /////////////////////////////  
  52.     // 3. add your codes below...  
  53.   
  54.     // add a label shows "Hello World"  
  55.     // create and initialize a label  
  56.     CCLabelTTF* pLabel = CCLabelTTF::create("Hello World", "Thonburi", 34);  
  57.   
  58.     // ask director the window size  
  59.     CCSize size = CCDirector::sharedDirector()->getWinSize();  
  60.   
  61.     // position the label on the center of the screen  
  62.     pLabel->setPosition( ccp(size.width / 2, size.height - 20) );  
  63.   
  64.     // add the label as a child to this layer  
  65.     this->addChild(pLabel, 1);  
  66.   
  67.     // add "HelloWorld" splash screen"  
  68.     CCSprite* pSprite = CCSprite::create("HelloWorld.png");  
  69.   
  70.     // position the sprite on the center of the screen  
  71.     pSprite->setPosition( ccp(size.width/2, size.height/2) );  
  72.   
  73.     // add the sprite as a child to this layer  
  74.     this->addChild(pSprite, 0);  
  75.       
  76.     // loading边框  
  77.     m_progressFrame = CCSprite::create("loading_fr.png");  
  78.     addChild(m_progressFrame,1);  
  79.     m_progressFrame->setPosition(ccp(240, 50));  
  80.       
  81.     // loading的动作条  
  82.     m_progressBar = CCProgressTimer::create(CCSprite::create("loading_bar.png"));  
  83.     m_progressBar->setType(kCCProgressTimerTypeBar);  
  84.     addChild(m_progressBar);  
  85.     m_progressBar->setVisible(true);  
  86.     m_progressBar->setPosition(ccp(241, 51));  
  87.     // 进度动画运动方向,从左到右  
  88.     m_progressBar->setMidpoint(ccp(0, 0));  
  89.     // 宽高变化,这里是宽度变化  
  90.     m_progressBar->setBarChangeRate(ccp(1, 0));  
  91.     m_progressBar->setPercentage(0);  
  92.       
  93.     // loading动画,没有逻辑处理,实际情况则凝视掉  
  94.     CCProgressTo *to = CCProgressTo::create(10, 100);  
  95.     m_progressBar->runAction(to);  
  96.       
  97.     // 实际的loading逻辑,能够在这里加入  
  98. //    scheduleUpdate();  
  99.     return true;  
  100. }  
  101.   
  102. void HelloWorld::update(float dt)  
  103. {  
  104.       
  105.     m_iLoadIdex++;  
  106.       
  107.     if (m_iLoadIdex <= 50) {  
  108.         loadResource(m_iLoadIdex);  
  109.         m_progressBar->setPercentage(m_iLoadIdex * 100.0 / 50);  
  110.     }  
  111.       
  112.     if (m_iLoadIdex >=50) {  
  113.         unscheduleUpdate();  
  114.     }  
  115. }  
  116.   
  117. // 实际的loading逻辑。载入资源能够在这里加入。

      

  118. // 这里仅仅用了sleep来模拟  
  119. void HelloWorld::loadResource(int index)  
  120. {  
  121.     CCLog("loading ....");  
  122.     switch (index) {  
  123.         case 0:  
  124.             break;  
  125.         default:  
  126.             sleep(1.0);  
  127.             break;  
  128.     }  
  129. }  
  130.   
  131.   
  132. void HelloWorld::menuCloseCallback(CCObject* pSender)  
  133. {  
  134.     CCDirector::sharedDirector()->end();  
  135.   
  136. #if (CC_TARGET_PLATFORM == CC_PLATFORM_IOS)  
  137.     exit(0);  
  138. #endif  
  139. }  

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

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

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

    个人原创,欢迎转载:http://blog.csdn.net/dawn_moon/article/details/11478885 这个资源加载的loading界面demo是在玩客网做逆转三国的时候随 ...

  2. unity3D游戏开发十八之NGUI动画

    我们先来看下帧动画,顾名思义,就是一帧帧的图片组成的动画,我们须要用到UISprite Animation组件,它的属性例如以下: Framerate:播放速率,也就是每秒钟播放的帧数 Name Pr ...

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

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

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

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

  5. Unity 2D游戏开发教程之游戏精灵的开火状态

    Unity 2D游戏开发教程之游戏精灵的开火状态 精灵的开火状态 “开火”就是发射子弹的意思,在战争类型的电影或者电视剧中,主角们就爱这么说!本节打算为精灵添加发射子弹的能力.因为本游戏在后面会引入敌 ...

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

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

  7. 《C++游戏开发》笔记十一 平滑动画:不再颤抖的小雪花

    本系列文章由七十一雾央编写,转载请注明出处.  http://blog.csdn.net/u011371356/article/details/9430645 作者:七十一雾央 新浪微博:http:/ ...

  8. STC8H开发(十五): GPIO驱动Ci24R1无线模块

    目录 STC8H开发(一): 在Keil5中配置和使用FwLib_STC8封装库(图文详解) STC8H开发(二): 在Linux VSCode中配置和使用FwLib_STC8封装库(图文详解) ST ...

  9. [Unity3D]Unity3D游戏开发Lua随着游戏的债券(于)

    ---------------------------------------------------------------------------------------------------- ...

随机推荐

  1. IDEA工具实现反编译操作

    1.File - Settings... 2.在搜索框中输入“byte” - 勾选 Java Byte code Decompiler选项 点击 OK 键 3.弹出重启IDEA的选择框 选择“rest ...

  2. H5C3--设置颜色的几种方式

    设置颜色的方式: 关键字:red|blue 第一种:十六进制:#ffffff 第二种:rgb(红,绿,蓝): rgb(ffff00) rgba(红,绿,蓝,透明度) 第三种:hsl(色相,饱和度,明度 ...

  3. JS 重载页面,本地刷新,返回上一页

    JS 重载页面,本地刷新,返回上一页 : <a href="javascript:history.go(-1)">返回上一页</a> <a href= ...

  4. 基于jquery实现图片上传本地预览功能

    一.原理 分为两步: 当上传图片的input被触发并选择本地图片之后获取要上传的图片这个对象的URL(对象URL),把对象URL赋值给事先写好的img标签的src属性即可把图片显示出来.在这里,我们需 ...

  5. python基础--GIL全局解释器锁、Event事件、信号量、死锁、递归锁

    ps:python解释器有很多种,最常见的就是C python解释器 GIL全局解释器锁: GIL本质上是一把互斥锁:将并发变成串行,牺牲效率保证了数据的安全 用来阻止同一个进程下的多个线程的同时执行 ...

  6. CentOS7 安装 Nginx 1.12.1

    安装准备: nginx 依赖的一些 lib 库: yum install gcc-c++ yum install pcre pcre-devel yum install zlib zlib-devel ...

  7. 2019-2-14-VisualStudio-通过外部调试方法快速调试库代码

    title author date CreateTime categories VisualStudio 通过外部调试方法快速调试库代码 lindexi 2019-2-14 22:1:37 +0800 ...

  8. ELK学习目录

    DAY1.elasticsearch和kibana环境搭建以及简单介绍 A:环境搭建配置 (1)java虚拟机安装:https://www.cnblogs.com/studybrother/p/108 ...

  9. 移动端适配之二:visual viewport、layout viewport和ideal viewport介绍

    上一篇博文,可算把像素这个东西讲清楚了.在这篇博文里面,将继续介绍viewport相关的内容. 很多博客都会提到PPK所讲的三个viewport,有的讲的比较复杂,看的云里雾里,我这里也大概介绍一下, ...

  10. adb安装apk包时提示:device unauthorized

    adb install apk时提示device unauthorized,手机上还没出现usb是否允许调试的询问弹框: 解决方法: 1.cmd输入:adb kill-server,点击回车键 2.c ...