Every day in this world, we are verifying our insignificance, but we are trying to create and keep leaving our footprints in this picture of life. Maybe we will wait until the day when we grow old, the old days can only rely on memories of the day, you are lying in a wheelchair, constantly memories of the past, the pain of lovesickness can not forget, the sweetness of falling in love with your heart, the mouth of the mouth without a smile, the madness, enthusiasm, ideals, and aspirations of young people all turn into the wealth of life with the flow of time, more or less, as the afterglow of the sunset slowly disappears ..
(Will you die if you are not literary ?)
Well, I have been busy writing games and writing games every day recently, and the efficiency is not high. I have been thinking about how to optimize and control the logic and map data storage of the enemy in the past two days, it took two days to finish writing,Well, let's take a serious look. To sum up how to improve the efficiency of code writing: Do not refresh Weibo when writing code, do not open qq when writing code, and do not know when writing code.
Well, that's it!
========================================================== ========================
The above is purely nonsense. Well, nonsense... (Is it fun to talk nonsense ?)
We often encounter loading interfaces when playing games. As the name suggests, they are mainly used to pre-load resource files. First:
Well, it's ugly, but it's probably like this. After loading, open the game interface. <喎?http: www.bkjia.com kf ware vc " target="_blank" class="keylink"> VcD4KPHA + PGJyPgo8L3A + signature + svmvfi2yMz1zOHKvrXE 0KG/8r/weight + weight/weight + PHByZSBjbGFzcz0 = "brush: java;"> auto winSize = Director: getInstance () -> getWinSize (); // The background image auto background = Sprite: create (IMG_LOADINGBG); background-> setPosition (winSize. width/2, winSize. height/2); this-> addChild (background, 0); // loading text label _ loadingLabel = LabelTTF: create ("Loading... "," Arial ", 25); _ loadingLabel-> setPosition (winSize. width/2, winSize. height/2-50); this-> addChild (_ loadingLabel); // ControlSlider progress bar _ curProgress = 0; _ progressBar = ControlSlider: create ("bar_bg.png ", "bar.png", "bar_thumb.png"); _ progressBar-> setPosition (winSize. width/2, winSize. height/2); _ progressBar-> setTouchEnabled (false); _ progressBar-> setMinimumValue (0); _ progressBar-> setMaximumValue (100 ); _ progressBar-> setValue (0); this-> addChild (_ progressBar, 1); // The prompt box above the progress bar _ barTip = Sprite: create (IMG_LOADING_BAR_TIP ); _ barTip-> setPosition (winSize. width/2-_ progressBar-> getContentSize (). width/2, winSize. height/2 + 50); this-> addChild (_ barTip, 1); // prompt the text label _ barTipLabel = LabelTTF: create ("0% ", "Arial", 20); _ barTipLabel-> setPosition (_ barTip-> getContentSize (). width/2, _ barTip-> getContentSize (). height/2); _ barTip-> addChild (_ barTipLabel );
Then let it get started. Let's execute it for one hundred times. Haha
//interval,repeat,delaythis->schedule(schedule_selector(LoadingScene::loadingLogic),1.0 / 100 ,100,0.2f);
Each executionDynamically update the location and text tag information of the prompt boxIn 100th, another interface is opened. Well, that's easy ..
void LoadingScene::loadingLogic(float dt){_curProgress ++;if(_curProgress > 100){//begin the game choose sceneDirector::getInstance()->replaceScene(TransitionFade::create(0.5f,ChooseScene::createScene()));return;}_progressBar->setValue(_curProgress);int startX = _progressBar->getPositionX() - _progressBar->getContentSize().width / 2 +10 ;int unitX = _progressBar->getContentSize().width / 100;_barTip->setPositionX(startX + _curProgress * unitX);char str[10] = {0};sprintf(str,"%d%",_curProgress);_barTipLabel->setString(str);}
Sorry, do you think anything is wrong here? Okay, you found out,Where can I load good resources? And how is the percentage of the progress of resource loading calculated?
Okay, continue. For example, we have one hundred images...(Why not 99 images ?)
Void LoadingScene: onEnter () {Layer: onEnter (); // call back a ctor: getInstance ()-> getTextureCache () When an image resource is loaded () -> addImageAsync ("1.png", this, callfunc_selector (LoadingScene: loadingCallback ));......... director: getInstance ()-> getTextureCache ()-> addImageAsync ("100.png", this, callfunc_selector (LoadingScene: loadingCallback ));}
Then the callback function is implemented. Each time the prompt box's location and text tag information are dynamically updated, another interface is opened 100th times. Well, it's still that simple...
void LoadingScene::loadingCallback(){_curProgress ++;if(_curProgress > 100){//begin the game choose sceneDirector::getInstance()->replaceScene(TransitionFade::create(0.5f,ChooseScene::createScene()));return;}_progressBar->setValue(_curProgress);int startX = _progressBar->getPositionX() - _progressBar->getContentSize().width / 2 +10 ;int unitX = _progressBar->getContentSize().width / 100;_barTip->setPositionX(startX + _curProgress * unitX);char str[10] = {0};sprintf(str,"%d%",_curProgress);_barTipLabel->setString(str);}
In fact, the idea is almost the same,
The progress bar percentage is calculated based on the percentage (number of Loaded Images/total number of image resources), or the maximum progress bar value is set to the total number of image resources, slide As Much As You load ..
========================================
Well, that's it. It's a sleepy night ..Good night