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