Cocos2d-x_3.2 demo ---------- spritetest (2)

Source: Internet
Author: User
Tags addchild
1 class spritetestdemo: Public basetest 2 {3 protected: 4 STD: String _ title; // not used to 5 6 public: 7 spritetestdemo (void); 8 virtual ~ Spritetestdemo (void); 9 10 void restartcallback (ref * sender); // reset scenario callback 11 void nextcallback (ref * sender ); // callback 12 Void backcallback (ref * sender) in the next scenario; // callback 13 in the previous scenario 14 // overrides15 virtual STD: String title () const override; // Title 16 virtual STD: String subtitle () const override; // subtitle 17 virtual void onenter () override; // when entering the layer 18 };

Basetest class please see here http://www.cnblogs.com/studweijun/p/3978249.html

This class inherits the function of basetest to obtain the switching scenario and display title. After that, each test item class will inherit this class. Let's take a look at the implementation:

1 # define max_layer (sizeof (createfunctions)/sizeof (createfunctions [0]) // Number of test items 2/* next layer */3 layer * nextspritetestaction () 4 {5 sceneidx ++; 6 sceneidx = sceneidx % max_layer; // value range 0 to MAX_LAYER-1 7 8 auto layer = (createfunctions [sceneidx]) (); // C ++ 11 9 return layer; 10} 11/* Previous Layer */12 Layer * backspritetestaction () 13 {14 sceneidx --; 15 int Total = max_layer; 16 if (sceneidx <0) 17 sceneidx + = Tota L; 18 19 auto layer = (createfunctions [sceneidx]) (); 20 return layer; 21} 22/* reset Layer */23 Layer * restartspritetestaction () 24 {25 auto layer = (createfunctions [sceneidx]) (); 26 return layer; 27} 28 29 // ------------------------------------------------------------------ 30 // 31 // spritetestdemo32 // 33 // 34 35 spritetestdemo: spritetestdem O (void): basetest () {} 36 37 spritetestdemo ::~ Spritetestdemo (void) {} 38 39 STD: String spritetestdemo: Title () const40 {41 return "No title"; 42} 43 44 STD: String spritetestdemo :: subtitle () const45 {46 Return "; 47} 48 49 void spritetestdemo: onenter () 50 {51 basetest: onenter (); 52} 53 54 void spritetestdemo :: restartcallback (ref * sender) 55 {56 auto S = new spritetestscene (); 57 s-> addchild (restartspritetestaction ());
58 59 Director: getinstance ()-> replacescene (s); // Replace the scenario 60 s-> release (); 61} 62 63 void spritetestdemo :: nextcallback (ref * sender) 64 {65 auto S = new spritetestscene (); 66 s-> addchild (nextspritetestaction (); 67 Director: getinstance () -> replacescene (s); 68 s-> release (); 69} 70 71 void spritetestdemo: backcallback (ref * sender) 72 {73 auto S = new spritetestscene (); 74 s-> addchild (backspritetestaction (); 75 ctor: getinstance ()-> replacescene (s); 76 s-> release (); 77}

This is the implementation version of The besttest class, but it cannot be used independently. Because there is no content, other test items need to be inherited to have specific content, such as the title and subtitle.

 

Cocos2d-x_3.2 demo ---------- spritetest (2)

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.