cocos2d-x游戏开发(十五)游戏载入动画loading界面
这个资源载入的loading界面demo是在玩客网做逆转三国的时候随手写的,尽管我在那仅仅待了2个礼拜。可是也算參与了一个商业游戏项目了,学到不少东西。当时使用的cocos2d-x还是1.0版的,我用2.1.2的调试过了。
上图:
好了,非常easy,代码有凝视
上代码:
- #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界面
个人原创,欢迎转载:http://blog.csdn.net/dawn_moon/article/details/11478885 这个资源加载的loading界面demo是在玩客网做逆转三国的时候随 ...
- unity3D游戏开发十八之NGUI动画
我们先来看下帧动画,顾名思义,就是一帧帧的图片组成的动画,我们须要用到UISprite Animation组件,它的属性例如以下: Framerate:播放速率,也就是每秒钟播放的帧数 Name Pr ...
- 【读书笔记《Android游戏编程之从零开始》】19.游戏开发基础(游戏音乐与音效)
在一款游戏中,除了华丽的界面 UI 直接吸引玩家外,另外重要的就是游戏的背景音乐与音效:合适的背景音乐以及精彩的音效搭配会令整个游戏上升一个档次. 在 Android 中.常用于播放游戏背景音乐的类是 ...
- Unity 4.2.0 官方最新破解版(Unity3D 最新破解版,3D游戏开发工具和游戏引擎套件)
Unity是一款跨平台的游戏开发工具,从一开始就被设计成易于使用的产品.作为一个完全集成的专业级应用,Unity还包含了价值数百万美元的功能强大的游戏引擎.Unity作为一个游戏开发工具,它的设计主旨 ...
- Unity 2D游戏开发教程之游戏精灵的开火状态
Unity 2D游戏开发教程之游戏精灵的开火状态 精灵的开火状态 “开火”就是发射子弹的意思,在战争类型的电影或者电视剧中,主角们就爱这么说!本节打算为精灵添加发射子弹的能力.因为本游戏在后面会引入敌 ...
- Unity 2D游戏开发教程之游戏中精灵的跳跃状态
Unity 2D游戏开发教程之游戏中精灵的跳跃状态 精灵的跳跃状态 为了让游戏中的精灵有更大的活动范围,上一节为游戏场景添加了多个地面,于是精灵可以从高的地面移动到低的地面处,如图2-14所示.但是却 ...
- 《C++游戏开发》笔记十一 平滑动画:不再颤抖的小雪花
本系列文章由七十一雾央编写,转载请注明出处. http://blog.csdn.net/u011371356/article/details/9430645 作者:七十一雾央 新浪微博:http:/ ...
- STC8H开发(十五): GPIO驱动Ci24R1无线模块
目录 STC8H开发(一): 在Keil5中配置和使用FwLib_STC8封装库(图文详解) STC8H开发(二): 在Linux VSCode中配置和使用FwLib_STC8封装库(图文详解) ST ...
- [Unity3D]Unity3D游戏开发Lua随着游戏的债券(于)
---------------------------------------------------------------------------------------------------- ...
随机推荐
- 在Ubuntu Server 14.04上源码安装Odoo 9.0
1. 更新Ubuntu服务器软件源 sudo apt-get update #更新软件源 sudo apt-get dist-upgrade #更新软件包,自动查找依赖关系 sudo shutdown ...
- NOSQL数据库之 REDIS
NOSQL数据库之 REDIS 一.NOSQL 1.简介 NoSQL ,(Not Only SQL),泛指非关系型数据库. 特点: NoSQL 通常是以key-value形式存储, 不支持SQL语句, ...
- c++新特性实验(3)声明与定义:constexpr
1.作用 constexpr 声明一个函数或变量,它的值可以在编译时出现在常量表达式之中. 2.constexpr 变量要求 其类型必须是 字面类型 (LiteralType) . 它必须被立即初始化 ...
- scrollbar 滚动条
滚动条样式:自定义元素的滚动条 <!DOCTYPE html> <html> <head lang="en"> <meta charset ...
- 2016中国人工智能企业TOP100, CBinsight2016年100家人工智能公司
2016中国人工智能企业TOP100 不论在学界还是业界,均有代表人物对人工智能表示了担忧,如史蒂芬·霍金和比尔·盖茨.尽管如此,国内外科技巨头都积极发力人工智能,一波波创业者也相继涌入.人工智能成为 ...
- python应用文件读取写登录注册
#!/usr/bin/python3# -*- coding: utf-8 -*-# Author: zhw#读取文件中的内容def open_file(filename ,file_type , * ...
- 【CodeVS】【2004年NOIP全国联赛提高组】1057 津津的储蓄计划
1057 津津的储蓄计划 2004年NOIP全国联赛提高组 时间限制: 1 s 空间限制: 128000 KB 题目等级 : 青铜 Bronze 题目描述 Description 津津的零花钱一直都是 ...
- cf round 482D Kuro and GCD and XOR and SUM
题意: 开始有个空集合,现在有两种操作: $(1,x)$:给集合加一个数$x$,$x \leq 10^5$; $(2,x,k,s)$:在集合中找一个$a$,满足$a \leq s-x$,而且$k|gc ...
- 从0开始学习 GitHub 系列之「05.Git 进阶」
关于 Git 相信大家看了之前一系列的文章已经初步会使用了, 但是关于Git还有很多知识与技巧是你不知道的,今天就来给大家介绍下一些 Git 进阶的知识. 1. 用户名和邮箱 我们知道我们进行的每一次 ...
- OWIN启动类检测
每个OWIN应用程序都有一个启动类,可以在这个类里为应用程序管道指定组件.有不同的方式可以将启动类与运行时关联起来,这依赖于选择的托管模型(OwinHost,IIS,IIS-Express).本教程中 ...