Using Ccaction to realize the carousel draw

Source: Internet
Author: User

With the help of Cocos2dx's own Ccmoveby and Cceaseinout, the current popular carousel draw effect is realized.

Creates a secondary node node_projection_ that maps the ordinal pos of the selected Sprite in the turntable to the x-coordinate of the node_projection_. When Node_projection_ executes Ccmoveby, it refreshes the sprite state in the turntable by roll_update (float DT) of the callback function executed at each frame. The distance of the Node_projuction_ on the x-axis determines the position of the final highlight of the turntable.

1 voidLayerroll::roll (ccobject* Psender, cccontroleventEvent)2 {3     4Node_projection_->setposition (CCP (0,0));5Spr_num_ =5;6Roll_index_ =1+ rand ()%5;7     8     intrount_t =4; number of//round_time cycles9Roll_unit_l_ = +; Node_projection the length of the moving unitTen     intLength = roll_unit_l_*spr_num_*rount_t + roll_unit_l_*roll_index_; One    Acccallfunc* mend = Cccallfunc::create ( This, Callfunc_selector (layerroll::roll_end)); -ccmoveby* mov = ccmoveby::create (4.0f, CCP (length,0)); -      theccsequence* seq = ccsequence::create (cceaseinout::create (MOV,1.5f), mend, NULL); Cceaseinout Slow Speed effect -Node_projection_->runaction (seq); - Schedule (Schedule_selector (layerroll::roll_update)); -      + } -  + voidlayerroll::roll_end () A { at      - Unschedule (Schedule_selector (layerroll::roll_update)); - } -  - voidLayerroll::roll_update (floatDT) - { in     intpos = node_projection_->Getpositionx (); -pos = pos% (roll_unit_l_*spr_num_);  topos = pos/roll_unit_l_+1; +     if(pos = =1) -     { theSpr_1_->setscale (0.8f); *     } $     ElsePanax Notoginseng     { -Spr_1_->setscale (0.6f); the     } +     if(pos==2) A     { theSpr_2_->setscale (0.8f); +  -     } $     Else $     { -Spr_2_->setscale (0.6f); -  the     } -     if(pos==3)Wuyi     { theSpr_3_->setscale (0.8f); -  Wu     } -     Else About     { $Spr_3_->setscale (0.6f); -  -     } -     if(pos = =4) A     { +Spr_4_->setscale (0.8f); the  -     } $     Else the     { theSpr_4_->setscale (0.6f); the  the     } -     if(pos = =5) in     { theSpr_5_->setscale (0.8f); the  About     } the     Else the     { theSpr_5_->setscale (0.6f); +  -     } the}

The number of dials here is 5.

Using Ccaction to realize the carousel draw

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.