COCOS2DX 3.0 (multiple button buttons perform the same event distinction)

Source: Internet
Author: User

1 //2 //attgamepoker.hpp3 //Malagame4 //5 //Created by work on 2016/10/18.6 //7 //8 9 #ifndef attgamepoker_hppTen #defineAttgamepoker_hpp One  A#include <stdio.h> -#include <cocos2d.h> -  the  - classAttgamepoker: PublicCocos2d::layer - { -      + Private: -      +Cocos2d::ui::button * m_btnhold[5];//five x Buttons ACocos2d::sprite * m_holdglitter[5];//Glow Effect/* appears when the button is clicked, disappears when released * / at      -  Public: -      -     Virtual BOOLinit (); -      -     voidHOLDCB (Ref *psender, cocos2d::ui::widget::toucheventtype type);//declaring a Click event in  - Create_func (attgamepoker); to      + }; -  the #endif/* ATTGAMEPOKER_HPP */

1 //2 //ATTGamePoker.cpp3 //MalaGame394 //5 //Created by work on 2016/10/18.6 //7 //8 9#include"attgamepoker.hpp"Ten#include <SimpleAudioEngine.h> One  A using namespacecocos2d; - using namespaceCocos2d::ui; -  the BOOLAttgamepoker::init () - { -     if(!layer::init ()) -     { +         return false; -     } +      A      for(intI=0; i<5; i++) { atAuto Soundbg=cocos2d::ui::scale9sprite::createwithspriteframename ("Gobang_option_sound_off.png"); -m_btnhold[i]=controlbutton::create (soundbg); -M_btnhold[i]->setposition (50*I -); -M_btnhold[i], setenabled (false); -M_btnhold[i]->settag (i+ -)///Set Tag value for easy differentiation -M_btnhold[i]->addtoucheventlistener (Cc_callback_2 (ATTMYGAMESCENE::HOLDCB, This)); inM_holdglitter[i] = Static_cast<sprite *> (m_rootnode->getchildbyname (Stringutils::format ("att_8_glitter_%d", i))); -M_holdglitter[i]->setposition (50*I -); to  +M_holdglitter[i]->setvisible (false);//set the glow body to hide all -M_holdglitter[i]->settag (i+ $); the     } * ; $     Panax Notoginseng      -      the      +      A     return true; the } +  -  $ //How to implement touch events $ voidATTMYGAMESCENE::HOLDCB (Ref *psender, Cocos2d::ui::widget::toucheventtype type)//Warranty Card - { -      the     if(type = = Widget::toucheventtype::began)//Judging the type of click, the button is pressed into effect -     {Wuyi         intTag = ((button*) Psender)->gettag ();//by clicking on the event to get the tag value of the current button, this is the sentence to distinguish which button is currently responding to this event the          -          for(intI=0; i<5; i++) { WuM_holdglitter[i]->setvisible (false); -             if( $+i==tag+ -) {//judging by the tag value to get the Luminous Body wizard AboutM_holdglitter[i]->setvisible (true);//Let it show $             } -         } -     } -     Else if(type = = widget::toucheventtype::ended)//Effective when the button is released A     { +          the          for(intI=0; i<5; i++) { -              $M_holdglitter[i]->setvisible (false);//Hide all when you send it away the              the         } the     } the          -      in  the}

COCOS2DX 3.0 (multiple button buttons perform the same event distinction)

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.