代码改变世界

cocos2dx 3.x(加载cocostudio进度条)

2016-10-21 00:46  罗任德  阅读(1544)  评论(0编辑  收藏  举报
 1 //
 2 //  MyLoagingScene.hpp
 3 //  My
 4 //
 5 //  Created by work on 16/10/13.
 6 //
 7 //
 8 
 9 #ifndef MyLoagingScene_hpp
10 #define MyLoagingScene_hpp
11 
12 #include <stdio.h>
13 #include "cocos2d.h"
14 #include <editor-support/cocostudio/CocoStudio.h>
15 #include "ui/cocosGUI.h"  //加载视图框架
16 
17 class MyLoagingScene : public cocos2d::Layer
18 {
19     
20     
21 private:
22     
23     cocos2d::Node* m_loginNode;  //初始化当前场景的节点
24     
25     cocos2d::ui::LoadingBar * m_loadingBar; //声明进度条私有成员变量
26     
27     cocos2d::ui::TextAtlas* m_percent;  //声明艺术字私有成员变量
28     
29 public:
30     static cocos2d::Scene* createScene();
31     
32     virtual bool init();
33     
34     void update(float dt);  //帧循环调用方法
35 
36 
37     // implement the "static create()" method manually
38     CREATE_FUNC(MyLoagingScene);
39 };
40 
41 #endif /* MyLoagingScene_hpp */

 

 

 

 1 //
 2 //  MyLoagingScene.cpp
 3 //  My
 4 //
 5 //  Created by work on 16/10/13.
 6 //
 7 //
 8 
 9 #include "MyLoagingScene.hpp"
10 #include "SimpleAudioEngine.h"
11 #include "MyGameScene.hpp"
12 USING_NS_CC;
13 
14 Scene* MyLoagingScene::createScene()
15 {
16     // 'scene' is an autorelease object
17     auto scene = Scene::create();
18     
19     // 'layer' is an autorelease object
20     auto layer = MyLoagingScene::create();
21     
22     // add layer as a child to scene
23     scene->addChild(layer);
24     
25     // return the scene
26     return scene;
27 }
28 
29 
30 bool MyLoagingScene::init()
31 {
32     //////////////////////////////
33     // 1. super init first
34     if ( !Layer::init() )
35     {
36         return false;
37     }
38     
39     
40     
41     m_loginNode=CSLoader::createNode("MyLoagingScene.csb");
42     this->addChild(m_loginNode);
43     
44     m_loadingBar=static_cast<cocos2d::ui::LoadingBar*>(m_loginNode->getChildByName("LoadingBar_1")); //获取cab里进度条
45     m_percent = static_cast<cocos2d::ui::TextAtlas*>(m_loginNode->getChildByName("LB_loading")); // 获取cab 里的进度显示艺术字
46     
47     
48 //    this-> schedule(schedule_selector(MyLoagingScene::update), 0.05);   // 自定义定时器,可自主设置时间拼了吧
49     scheduleUpdate();   // 系统的定时器
50     return true;
51 }
52 
53 
54 
55 void MyLoagingScene::update(float dt){
56     
57 
58     int num = m_loadingBar ->getPercent();//获取进度条的当前进度
59     m_loadingBar->setPercent(++num); //使进度增加
60     
61 //    auto ns=__String::createWithFormat("%d",num);  //强转,将 int 类型转化为字符串String类型
62     
63 //    m_percent->setString(cocos2d::StringUtils::format("%d",(int)m_loadingBar->getPercent())); // 改变进度条上的艺术字
64     
65     m_percent->setString(cocos2d::StringUtils::format("%d%c",(int)m_loadingBar->getPercent(),'9'+1));
66     
67     if(num >= 100){
68          //判断当前进度自动跳转
69         Scene* gameScene = MyGameScene::createScene();
70         Director::getInstance()->replaceScene(gameScene);
71         
72     }
73     
74     
75 }