COCOS2D Game Select the interface with the source code

Source: Internet
Author: User

1. Check off

15 per page, 45 total, 5 per line. These can all be changed. Source code based on Cocos2d 3.3.   2. Principle of Implementation Anyway, there is the source of the less talk about the point. I look at the implementation of the Cocos2d menu, is a layer, and then add a lot of MenuItem inside, if it is the default way to add, this few rows of a few columns of difficult to engage, so we just need to create an empty menu, and then in our way one by one add MenuItem can.   [CPP]View Plaincopy
  1. void levelselectcontent::initalllevels (int page) {
  2. This->removeallchildren ();
  3. const int eachpageitemcount = G_eachpagecount;
  4. _levelmenu = Menu::create ();
  5. This->addchild (_levelmenu);
  6. int Const CONSTSTARTPOSITIONX = visible_width * 0.5-levelmarginx * (G_EACHLINECOUNT/2-0.5);
  7. int startpositionx = Conststartpositionx;
  8. int topstartpositiony = visible_height * 0.5 + levelmarginy * (G_EACHPAGECOUNT/G_EACHLINECOUNT/2-0.5);
  9. For (int i = 0 + page * eachpageitemcount; i < Eachpageitemcount + page * eachpageitemcount; i++) {
  10. if (i < g_maxlevel) {
  11. int linecount = G_eachlinecount;
  12. if (i!= (0 + page * eachpageitemcount) && i% LineCount = 0) {
  13. Startpositionx = Conststartpositionx;
  14. Topstartpositiony = Topstartpositiony-levelmarginy;
  15. }
  16. int levelcount = i + 1;
  17. Auto Onelevelitem = levelselectitem::create (Levelcount);
  18. _levelmenu->addchild (Onelevelitem);
  19. Onelevelitem->setposition (Startpositionx, topstartpositiony);
  20. Startpositionx + = Levelmarginx;
  21. }
  22. }
  23. _levelmenu->setposition (0, 0);
  24. _levelmenu->setopacity (0);
  25. Auto Fadeaction = fadein::create (0.5);
  26. _levelmenu->runaction (fadeaction);
  27. }

The essence is a for loop, adding a MenuItem   3. Custom Menuitemsprite we have 3 states for each of our chosen customs, which have been completed, will be completed, and locked. Assuming that the user has completed the 5th level, then the first 5 off is completed, the 6th is going to be completed, the back of all is locked. So here's a definition of an enumeration [CPP]View Plaincopy
    1. typedef enum{
    2. Kalreadypass,
    3. Knotpassyet,
    4. Klocklevel
    5. }levelitemtype;

[CPP]View Plaincopy
  1. Levelselectitem::levelselectitem (int): _level (Level), _type (klocklevel) {
  2. if (Level > (G_passlevelcount + 1)) {
  3. this->setenabled (false);
  4. _type = Klocklevel;
  5. }Else if (level = = (G_passlevelcount + 1)) {
  6. this->setenabled (true);
  7. _type = Knotpassyet;
  8. }Else if (Level < (G_passlevelcount + 1)) {
  9. this->setenabled (true);
  10. _type = Kalreadypass;
  11. }
  12. }

You can decide what you want based on the number of levels. COCOS2D supports 3 image styles by default, Normal, selected, disabled, so you only need to set the back level MenuItem to be unavailable.  or directly look at the source code, do not rip, see the source is relatively clear.

COCOS2D Game Select the interface with the source code

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.