COCOS2DX implementing Global Game Announcements

Source: Internet
Author: User

At the beginning of the platform call native hints, but because the content to be displayed after the project becomes complex, we have to study the overall game announcement how to show.

Direct Addchild is not feasible, or processing is cumbersome, because each time the scene will be emptied.

This paper studies the rendering mechanism of COCOS2DX.

Entrance:

Ccapplication::sharedapplication ()->run ()
Ccdirecor Cycle Executes a mainloop

int Ccapplication::run () {Pvrframeenablecontrolwindow (false);    Main message loop:msg MSG;    Large_integer Nfreq;    Large_integer Nlast;    Large_integer Nnow;    QueryPerformanceFrequency (&nfreq);    QueryPerformanceCounter (&nlast);    Initialize instance and cocos2d.    if (!applicationdidfinishlaunching ()) {return 0;    } cceglview* pMainWnd = Cceglview::sharedopenglview ();    Pmainwnd->centerwindow ();    ShowWindow (Pmainwnd->gethwnd (), sw_show); while (1) {if (!            PeekMessage (&msg, NULL, 0, 0, pm_remove)) {//Get current time tick.            QueryPerformanceCounter (&nnow);            If it ' s the time to draw next frame, draw it, else sleep a while. if (Nnow.quadpart-nlast.quadpart > M_nanimationinterval.quadpart) {nlast.quadpart = Nnow.q                Uadpart;            Ccdirector::shareddirector ()->mainloop ();         } else {       Sleep (0);        } continue;            } if (wm_quit = = msg.message) {//QUIT message loop.        Break        }//Deal with Windows message. if (! m_hacceltable | |!            TranslateAccelerator (Msg.hwnd, m_hacceltable, &msg)) {translatemessage (&msg);        DispatchMessage (&MSG); }} return (int) Msg.wparam;}
Mainloop will draw the current scene:

void Ccdisplaylinkdirector::mainloop (void) {    if (m_bpurgedirecotorinnextloop)    {        m_ Bpurgedirecotorinnextloop = false;        Purgedirector ();    }    else if (! M_binvalid)     {         drawscene ();              Release the Objects         Ccpoolmanager::sharedpoolmanager ()->pop ();             }
The point is that there is a m_pnotificationnode inside the Drawscene:

Draw the scenevoid ccdirector::d rawscene (void) {//calculate "global" DT calculatedeltatime ();    Tick before Glclear:issue #533 if (! m_bpaused) {m_pscheduler->update (m_fdeltatime); } glclear (Gl_color_buffer_bit |    Gl_depth_buffer_bit);     /* To avoid Flickr, nextscene must is here:after tick and before draw. Xxx:which Bug is this one.    It seems that it can ' t is reproduced with v0.9 */if (m_pnextscene) {setnextscene ();    } Kmglpushmatrix ();    Draw the scene if (m_prunningscene) {m_prunningscene->visit ();    }//Draw the Notifications node if (M_pnotificationnode) {m_pnotificationnode->visit ();    } if (m_bdisplaystats) {showstats ();    } Kmglpopmatrix ();    m_utotalframes++;    Swap buffers if (M_pobopenglview) {m_pobopenglview->swapbuffers ();    } if (m_bdisplaystats) {Calculatempf (); }}
View M_pnotificationnode Definitions

/* This object is visited after the scene. Useful to hook a notification node */    Ccnode *m_pnotificationnode;
So create a game announcement layer:

noticeboard* noticeboard = noticeboard::create ();pD irector->setnotificationnode (noticeboard);
This allows two lines of code to achieve a global game announcement, not affected by the switching scene.





COCOS2DX implementing Global Game Announcements

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.