본문 바로가기

Cocos2d-x v3.17/기본기능

[Cocos2d-x 기본기능]UI 컴포넌트 LoadingBar

반응형

LoadingBar 

 

당신이 자주 게임을 한다면 꼭 봤을법한 장면이 있다.

화면에 로딩바가 등장하고 리소스가 로딩되는 속도를 보여주는것이다.

Cocos2d-x는 Loadingbar객체를 제공하여 로딩바를 구현한다. 

 

로딩바 생성 

C++ 

#include "ui/CocosGUI.h" 

auto loadingBar = LoadingBar::create("LoadingBarFile.png"); 

// set the direction of the loading bars progress

loadingBar->setDirection(LoadingBar::Direction::RIGHT); 

this->addChild(loadingBar); 

 

위의 예제에서 우린 로딩바를 생성하고 진도가 나갈때 우측으로 증가하라고 설정해줬다.

진도를 컨트롤하기위해선 당신은 로딩바의 진도를 설정해줘야 할 필요가 있다.

아래 예제를 보자 

C++ 

#include "ui/CocosGUI.h" 

auto loadingBar = LoadingBar::create("LoadingBarFile.png");

loadingBar->setDirection(LoadingBar::Direction::RIGHT); 

// something happened, change the percentage of the loading bar

loadingBar->setPercent(25); 

// more things happened, change the percentage again.

loadingBar->setPercent(35); 

this->addChild(loadingBar); 

 

위의 예에서 로딩바의 이미지는 아래 이미지와 같다.

 

스크린으로 보이는 로딩바의 모습은 아래와 같다.


출처: <http://cocos2d-x.org/docs/cocos2d-x/zh/ui_components/loading_bar.html

 


반응형