A skill in online games

Source: Internet
Author: User
When developing an online game client, we often open a thread to receive and send network messages. At this time, we will inevitably encounter some problems, such: players can be online or offline in some battle lists at any time. In this case, we should involve the synchronization problem between the UI thread (main thread) and network thread: If you directly obtain data in the network thread, you can use it directly.

When developing an online game client, we often open a thread to receive and send network messages. At this time, we will inevitably encounter some problems, such: players can be online or offline in some battle lists at any time. In this case, we should involve the synchronization problem between the UI thread (main thread) and network thread: If you directly obtain data in the network thread, you can use it directly.

When developing an online game client, we often open a thread to receive and send network messages. At this time, we will inevitably encounter some problems, such:

Players can be online or offline in some battle lists at any time. At this time, we should be involved in the synchronization of the UI thread (main thread) and network thread:

If you directly use the data obtained in the network thread, there will certainly be various strange problems. So a common practice is:

Use a variable to judge: m_bFresh

Void UserList: visit (void)
{
CCLayer: visit ();
If (m_bFresh ){
UpDataUserList ();
}
M_bInGame = true;
}

Because visit will always be called, you just need to click it to refresh it.

Void UserList: upDataUserList ()
{
M_pUserList = NET_MANAGER-> getUserList (); this is the latest data.
M_pTableView-> reloadData ();
M_bFresh =! M_bFresh;
}

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.