cocos2dx3.x "Fighting" Game Loading Interface (i)

Source: Internet
Author: User
Tags addchild

The final renderings are as follows:


COCOS2DX version: cocos2d-x3.8
IDE Version: VS2013
First create the project using the Cocos command:

Cocos New Gedou-p com.zhenqi.game-l cpp-d F:\cocos2d-xProject


Double-click it

Create a new scene Loadingscene
The LoadingScene.h file is defined as follows

#ifndef __loading_scene_h__
#define __LOADING_SCENE_H__

#include "ui/cocosgui.h"

#include "cocos2d.h"
using_ns_cc;

Class Loading:public Layer
{public
:
    static scene* createscene ();
    virtual BOOL init ();

    Set the progress bar
    void Setpro (float frate);
    Resource preload
    void Loadrec ();
    Resource preload callback function
    void Onloadarmaturedata (float percent);
    Resource load callback
    void Onloadreccallback (Object *pobj);

    Create_func (Loading);

Protected:
    int m_nloadrecnum;              The number of resource loads
    int m_nloadrectotalnum;         Total resource load

    ui::loadingbar* Pproloadrec;    progress bar
};

The implementation of the Init method is basically adding a picture.

BOOL Loading::init () {if (!
    Layer::init ()) {return false;
    } Size visiblesize = Director::getinstance ()->getvisiblesize ();

    VEC2 origin = Director::getinstance ()->getvisibleorigin ();
    Size size = Director::getinstance ()->getwinsize ();                                                /************************************************************************//* Background image
    *//************************************************************************///People pictures
    Auto PPERSONBG = sprite::create ("Ui/loading_bg.png");
    Ppersonbg->setposition (CCP (size.width*0.5f, size.height*0.5f));

    AddChild (PPERSONBG, 100);
    Create logo map Auto Plogo = sprite::create ("Ui/logo_bg.png");
    Plogo->setscale (0.95f);
    Plogo->setposition (CCP (size.width*0.5f, 410));

    AddChild (Plogo, 100);                                       /************************************************************************//* progress bar           *//************************************************************************///Create load progress bar background Auto Ppro
    Bg = Sprite::create ("Ui/loading_progress_bg.png");
    Pprobg->setposition (CCP (size.width*0.5f, 100));

    AddChild (PPROBG, 100000);
    Pproloadrec = Ui::loadingbar::create ("Ui/loading_progress_bar.png");
    Pproloadrec->setposition (Pprobg->getposition ());
    Pproloadrec->setdirection (Ui::loadingbar::D irection::left);
    Pproloadrec->setpercent (0);
    AddChild (Pproloadrec, 100001, 1);//Set the tag value to 1 auto plight = Sprite::create ("Ui/loading_progress_light.png");
    AddChild (Plight, 300000, 2); Plight->setposition (CCP (Pproloadrec->getpositionx ()-pproloadrec->getcontentsize (). width*0.5f,

    Pproloadrec->getpositiony ()));
    M_nloadrecnum = 0;

    M_nloadrectotalnum = 16;

    Preload this Layer resource loadrec ();
return true; }

Then look at the Loadrec () method, implemented as follows:
For the Armaturedatamanager class application, first add the header file.

#include "cocostudio/cocostudio.h"
using namespace Cocostudio;
Resource preload void Loading::loadrec () {texturecache::getinstance ()->addimageasync ("Ui/serverselect_bg.png", CC_

    Callback_1 (Loading::onloadreccallback,this)); Armaturedatamanager::getinstance ()->addarmaturefileinfoasync ("Armature/kulougongshou.
    Exportjson ", This,schedule_selector (Loading::onloadarmaturedata,this)); Armaturedatamanager::getinstance ()->addarmaturefileinfoasync ("Armature/kulouzhanshi.
    Exportjson ", this, Schedule_selector (Loading::onloadarmaturedata, this)); Armaturedatamanager::getinstance ()->addarmaturefileinfoasync ("Armature/mayi.
    Exportjson ", this, Schedule_selector (Loading::onloadarmaturedata, this)); Armaturedatamanager::getinstance ()->addarmaturefileinfoasync ("Armature/bianyikunchong.

    Exportjson ", this, Schedule_selector (Loading::onloadarmaturedata, this)); Armaturedatamanager::getinstance ()->addarmaturefileinfoasync ("armature/bubing.
    Exportjson ", this, Schedule_selector (Loading::onloadarmaturedata, this)); Armaturedatamanager::getInstance ()->addarmaturefileinfoasync ("Armature/xiaoyin.
    Exportjson ", this, Schedule_selector (Loading::onloadarmaturedata, this)); Armaturedatamanager::getinstance ()->addarmaturefileinfoasync ("Armature/newproject.exportjson", this, schedule
    _selector (Loading::onloadarmaturedata, this)); Armaturedatamanager::getinstance ()->addarmaturefileinfoasync ("Armature/minren1.

    Exportjson ", this, Schedule_selector (Loading::onloadarmaturedata, this)); Armaturedatamanager::getinstance ()->addarmaturefileinfoasync ("Armature/kulou_arrow.
    Exportjson ", this, Schedule_selector (Loading::onloadarmaturedata, this)); Armaturedatamanager::getinstance ()->addarmaturefileinfoasync ("Armature/naili.
    Exportjson ", this, Schedule_selector (Loading::onloadarmaturedata, this)); Armaturedatamanager::getinstance ()->addarmaturefileinfoasync ("Armature/npc_kakaxi.
    Exportjson ", this, Schedule_selector (Loading::onloadarmaturedata, this)); Armaturedatamanager::getinstance ()->addarmaturefileiNfoasync ("Armature/portal.

    Exportjson ", this, Schedule_selector (Loading::onloadarmaturedata, this)); Armaturedatamanager::getinstance ()->addarmaturefileinfoasync ("Armature/hited_light.
    Exportjson ", this, Schedule_selector (Loading::onloadarmaturedata, this)); Armaturedatamanager::getinstance ()->addarmaturefileinfoasync ("armature/public_casting.
    Exportjson ", this, Schedule_selector (Loading::onloadarmaturedata, this)); Armaturedatamanager::getinstance ()->addarmaturefileinfoasync ("Armature/skill_light_1.exportjson", this,
Schedule_selector (Loading::onloadarmaturedata, this)); }

Here is the callback function:

void Loading::onloadarmaturedata (float percent) {
    m_nloadrecnum++;
    Setpro (float) m_nloadrecnum/(float) m_nloadrectotalnum);
    If (Percent >= 1)
    {
        Cclog ("Addarmaturefileinfoasync over");
    }
}

void Loading::onloadreccallback (Object *pobj) {
    do
    {
        m_nloadrecnum++;
        Setpro (float) m_nloadrecnum/(float) m_nloadrectotalnum);
        return;
    } while (false);
    Cclog ("Fun cnfloginscene::onloadreccallback error!");
}

Finally, take a look at this setpro method, which is to set progress bar progress.

void Loading::setpro (float frate)
{
    do
    {
        pproloadrec->setpercent (frate *);

        Sync Light point
        auto plight = Dynamic_cast<sprite *> (Getchildbytag (2));
        if (plight! = NULL)
            Plight->setpositionx (Pproloadrec->getpositionx () + pproloadrec->getcontentsize (). width* (frate-0.5f));

        If the load is complete
        if (frate >= 1)
        {
            Auto Pdiclang = Dictionary::createwithcontentsoffile ("Ui_xml/loading_ Xml.xml ");

            Get load Information label
            auto pstrloading = dynamic_cast<string*> (Pdiclang->objectforkey ("Loading_end"));
            Auto plabelloading = Dynamic_cast<labelttf *> (Getchildbytag (3));
        }

        return;
    } while (false);
    Cclog ("Fun Cnfloadinglayer::setpro error!");
}

The following will complete the character selection screen. To be continued in ...

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.