Multithreading in cocos2dx

Source: Internet
Author: User

We recommend that you use pthreadcc. The method has been encapsulated For ease of use, and there is no need to worry about thread concurrency and deadlock issues. During android development

I am familiar with a class called AsyncTask. Today, I encapsulated a similar class to be called by a project developer. The idea is:

Upload a url or pMsg, enable a thread to execute the network request, and notify the main thread to update,


The use of threads is smooth, but when the thread is combined with 2dx, it is found that the OpenGL rendering thread only allows rendering in the main thread, and suddenly think of Android

The same is true. At the beginning, no image in 2dx drawing is displayed.


Later, the thread and CCLayer were encapsulated, which worked well, but the OpengGL rendering was affected. The rendered image was a black box every time,

Color, very depressing.


With some understanding of OpengGL and some experience in mobile game development, I suddenly thought of rendering 2dx first, then executing the thread and modifying the code.

Executed.


Tip: When OpenGL is combined with a thread, You need to load the Sprite you need to render to the memory first. You can set it to not display, and then after the thread is executed

Set the Wizard to display the status to solve the problem that the thread is incompatible with the OpneGL rendering.


:

Before execution, a dialog box is displayed, prompting you to load data. Now the asynchronous loading status is displayed.




<Strong? Http: www.bkjia.com kf ware vc "target =" _ blank "class =" keylink "> VcD4KPHA + tbEg1rTQ0M3quvOjrM2o1qrW98/fs8zatlj80mkjuw.vcd4kpha + pgltzybzcm9 "http://www.bkjia.com/uploadfile/Collfiles/20131223/2013122309500422.jpg" alt = "">

Related Article

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.