Cocos2d-x mobile game R & D ---- gaming big Turntable

Source: Internet
Author: User

I want to separate the turntable system into a class folder, which can be plugged and easily connected to any game in the future. I have created a folder named ZhuanPanSystem. Let's talk about the general idea, first, you need a grid to form a rectangular matrix. You can set the length and width based on your needs. There is a button in the middle. After clicking it, the grid will change to the background, and cyclically run on the rectangular lattice, and finally get the reward on the Lattice Based on the speed from fast to slow, check how the code is implemented; check: copy the code // create a matrix lattice array boxgezi = CCArray: create (); int bid = 0; for (int I = 0; I <4; I ++) {for (int j = 0; j <= 5; j ++) {Zp_BoxData * thisbox = new Zp_BoxData (); thisbox-> set_boxid (bid); thisbox-> set_boxReward (getReward (bid % 6); if (bid = 4) {thisbox-> set_xuanzhong (true );} else {thisbox-> set_xuanzhong (false);} thisbox-> set_tag (bid); switch (I) {case 0: thisbox-> set_point (ccp (55 + gezi_w * j, allbd_h-30); boxgezi-> addObject (thisbox); break; case 1: if (j <= 2) {thisbox-> set_point (ccp (55 + gezi_w * 5, allbd_h-30-gezi_h-gezi_h * j); boxgezi-> addObject (thisbox);} break; case 2: thisbox-> set_point (ccp (55 + gezi_w * 5-gezi_w * j, 30 )); boxgezi-> addObject (thisbox); break; case 3: if (j <= 2) {thisbox-> set_point (ccp (55,30 + gezi_h * j )); boxgezi-> addObject (thisbox);} break; default: break;} bid ++ ;}} vector <int> maua; for (int I = 0; I <boxgezi-> count (); I ++) {Zp_BoxData * bdata = (Zp_BoxData *) boxgezi-> objectAtIndex (I); Gzi * gz = new Gzi (allbd, bdata); maua. push_back (bdata-> get_boxid ();} copy the code. The above is a matrix Turntable with a rectangular range created using the Gzi class, with a rectangular turntable, you also need the effect of loop rotation after the click starts in the game. You can use a recursive method to loop to run an acceleration effect: copy the code void TurntableSystem: runTurntableGet (float time) {this-> schedule (schedule_selector (TurntableSystem: runAct), time);} void TurntableSystem: runAct (float time) {vector <int> gezi_l = GlobalInfo: getInstance () -> get_gizilist (); // if (gezi_l.size ()> 0) {if (fnum> gezi_l.size ()-1) {fnum = 0 ;} int bid = gezi_l.at (fnum); changeBox (bid, true); // change the previous one back to int lastnum = fnum-1; if (lastnum <0) {lastnum = gezi_l.size () -1;} int lastid = gezi_l.at (lastnum); changeBox (lastid, false); fnum ++;} runnum ++; this-> unschedule (schedule_selector (TurntableSystem :: runAct); CCLOG ("------ % f ---- times = % d-", time, runnum); if (runnum <25) {float nexttime = time + runnum * 0.01f; if (nexttime >=1.5f) {nexttime = 1.5f;} this-> schedule (schedule_selector (TurntableSystem: runAct), nexttime );}}

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.