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)