cocos2d-x游戏开发(十五)游戏加载动画loading界面
个人原创,欢迎转载: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界面的更多相关文章
- cocos2d-x游戏开发(十五)游戏载入动画loading界面
这个资源载入的loading界面demo是在玩客网做逆转三国的时候随手写的,尽管我在那仅仅待了2个礼拜.可是也算參与了一个商业游戏项目了,学到不少东西.当时使用的cocos2d-x还是1.0版的,我用 ...
- WebGL简易教程(十五):加载gltf模型
目录 1. 概述 2. 实例 2.1. 数据 2.2. 程序 2.2.1. 文件读取 2.2.2. glTF格式解析 2.2.3. 初始化顶点缓冲区 2.2.4. 其他 3. 结果 4. 参考 5. ...
- Ionic Js十九:加载动画
ion-spinner ionSpinner 提供了许多种旋转加载的动画图标.当你的界面加载时,你就可以呈现给用户相应的加载图标. 该图标采用的是SVG.  实例 HTML 代码 <ion-c ...
- 【读书笔记《Android游戏编程之从零开始》】19.游戏开发基础(游戏音乐与音效)
在一款游戏中,除了华丽的界面 UI 直接吸引玩家外,另外重要的就是游戏的背景音乐与音效:合适的背景音乐以及精彩的音效搭配会令整个游戏上升一个档次. 在 Android 中.常用于播放游戏背景音乐的类是 ...
- Unity 4.2.0 官方最新破解版(Unity3D 最新破解版,3D游戏开发工具和游戏引擎套件)
Unity是一款跨平台的游戏开发工具,从一开始就被设计成易于使用的产品.作为一个完全集成的专业级应用,Unity还包含了价值数百万美元的功能强大的游戏引擎.Unity作为一个游戏开发工具,它的设计主旨 ...
- Unity 2D游戏开发教程之游戏中精灵的跳跃状态
Unity 2D游戏开发教程之游戏中精灵的跳跃状态 精灵的跳跃状态 为了让游戏中的精灵有更大的活动范围,上一节为游戏场景添加了多个地面,于是精灵可以从高的地面移动到低的地面处,如图2-14所示.但是却 ...
- iOS帅气加载动画、通知视图、红包助手、引导页、导航栏、朋友圈、小游戏等效果源码
iOS精选源码 如丝般顺滑的微信朋友圈(点赞,评论,图文混排表情,... 动态菜单第三版本:动态项,自适应方向 仿appstore首页滚动效果 iOS 透明导航栏方案 TransparentNavig ...
- (转)Unity3D游戏开发 NGUI之渐变加载到100%的Loading场景进度条
NGUI 现有的进度条存在的问题: 进度条跳跃式前进,加载到90%后卡住,突然进入下一个场景.接下来就是解决这个问题. 背景 通常游戏的主场景包含的资源较多,这会导致加载场景的时间较长.为了避免这个问 ...
- 微信小游戏 4M升8M分包加载
一.微信分包加载 微信分包加载教程 嘛,因为原来的4M太小了,满足不了小游戏内容的需求,现在提升到了8M.这8M可以分包加载,而不需要一次性加载8M. 如果是老版本,则分包加载不起作用,会一次加载8M ...
随机推荐
- Python基础 3----文件和网络
1 Python文件IO 1 标转的输入和输出 print 方法:输出数据到标准的输出 raw_input 方法:标准的输入 2 file文件类 读文件 f = file(文件名, 模式) 有5种模式 ...
- vsftpd安装
原文连接:史上最详细的vsftpd配置文件讲解: http://www.9170.org/post-322.html 参考博文:centos启用ftp功能:http://os.51cto.com/ar ...
- __get __set 实例
<?php class Person { //下面是人的成员属性,都是封装的私有成员 private $name; //人的名子 private $sex; //人的性别 private $ag ...
- Java--finally
finally 子句(clause)是不是总会执行??? package com.volshell.test; public class Main { public static void main( ...
- 关于QuartusII对ram块的综合
之前在看Altera的官方教程上就有说明,如果我们定义一个reg [`word_w]user_ram[`word_d] ; QuartusII会自动综合成为一个ram—— 当然有一些前提:(后续补充 ...
- 由基于qml,c++的串口调试工具浅谈qml与c++混合编程
最近在做一个基于sim900 的串口通信工具,基于qml和c++来实现. 首先,对于串口,qt有自带的QSerialPort,可以实现同步,和异步通信,qt creator也有自带的例子,本例子是从其 ...
- ASP.NET MVC 5 学习教程:添加查询
原文 ASP.NET MVC 5 学习教程:添加查询 起飞网 ASP.NET MVC 5 学习教程目录: 添加控制器 添加视图 修改视图和布局页 控制器传递数据给视图 添加模型 创建连接字符串 通过控 ...
- 转:C++ 匿名namespace的作用以及它与static的区别
匿名namespace的作用以及它与static的区别 一.匿名namespace的作用在C语言中,如果我们在多个tu(translation unit)中使用了同一个名字做为函数名或者全局变量名,则 ...
- Observer设计模式【利用商品概念解释】
每个人都想过着富有的生活,这是很正常的. 这里以开店进货为例. 在讲之前解释英语单词: Observer:查看:遵守 Observable:可见的,公开的. 从单词可以知道:商品用来卖,所以公开,继承 ...
- typedef 总结
其实在正儿八经学C语言的时候typedef用的不是很多,记得书上对它的介绍只是一笔带过.的确它的用法是很简单,但这不代表在使用的过程中不会出错,今天来个彻底的总结. 作用:用来建立新的数据类型名.(注 ...