//
// ATTGamePoker.hpp
// MalaGame
//
// Created by work on 2016/10/18.
//
// #ifndef ATTGamePoker_hpp
#define ATTGamePoker_hpp #include <stdio.h>
#include <cocos2d.h> class ATTGamePoker : public cocos2d::Layer
{ private: cocos2d::ui::Button * m_btnHold[];//五个按钮
cocos2d::Sprite * m_holdGlitter[];//发光特效/*按钮点下时出现,松开时消失*/ public: virtual bool init(); void holdCB(Ref *pSender, cocos2d::ui::Widget::TouchEventType type);//声明点击事件 CREATE_FUNC(ATTGamePoker); }; #endif /* ATTGamePoker_hpp */
 //
// ATTGamePoker.cpp
// MalaGame39
//
// Created by work on 2016/10/18.
//
// #include "ATTGamePoker.hpp"
#include <SimpleAudioEngine.h> using namespace cocos2d;
using namespace cocos2d::ui; bool ATTGamePoker::init()
{
if (!Layer::init())
{
return false;
} for (int i=; i<; i++) {
     auto 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+);//设置tag值便于区分
m_btnHold[i]->addTouchEventListener(CC_CALLBACK_2(ATTMyGameScene::holdCB, this));
m_holdGlitter[i] = static_cast<Sprite *>(m_rootNode->getChildByName(StringUtils::format("att_8_glitter_%d",i)));
m_holdGlitter[i] ->setPosition(50*i, ); m_holdGlitter[i]->setVisible(false);//设置发光体全部隐藏
m_holdGlitter[i]->setTag(i+);
}
; return true;
} //触摸事件的实现方法
void ATTMyGameScene::holdCB(Ref *pSender, cocos2d::ui::Widget::TouchEventType type)//保牌
{ if (type == Widget::TouchEventType::BEGAN)//判断点击类型,按钮按下生效
{
int tag = ((Button*)pSender)->getTag();//通过点击事件来获取当前按钮的tag值,就是这一句话来区分当前哪个button响应来此次事件 for (int i=; i<; i++) {
m_holdGlitter[i]->setVisible(false);
if (+i==tag+) {//判断通过tag值拿到发光体精灵
m_holdGlitter[i]->setVisible(true);//让其显示
}
}
}
else if (type == Widget::TouchEventType::ENDED)//按钮松开时生效
{ for (int i=; i<; i++) { m_holdGlitter[i]->setVisible(false);//送开时全部隐藏 }
} }

cocos2dx 3.x(多个按钮button执行同一事件的区分)的更多相关文章

  1. 消除点击连接或者按钮或者执行onclick事件时出现的边框

    css中添加 *:not(input) { font-family: sans-serif; font-size-adjust: none; -webkit-user-select: none; -w ...

  2. ASP.NET 解决在点击Button执行服务器事件之前验证用户输入并阻塞

    在网站项目开发时,为了减少用户的错误性的操作,很多时候我们都需要做一些必要的JS验证来提醒用户,比如:“输入的值不符合规则,请重新输入”.“提交后无法修改,您确定要继续吗?”友好性的提示. 这时候我们 ...

  3. .net学习之母版页执行顺序、jsonp跨域请求原理、IsPostBack原理、服务器端控件按钮Button点击时的过程、缓存、IHttpModule 过滤器

    1.WebForm使用母版页后执行的顺序是先执行子页面中的Page_Load,再执行母版页中的Page_Load,请求是先生成母版页的控件树,然后将子页面生成的控件树填充到母版页中,最后输出 2.We ...

  4. input 的blur事件之后button的onclick事件不执行解决方案

    最近发现网页程序中有个BUG,就是在input标签输入框中输入完数据后,直接点击“取消” 按钮的时候.出现网页崩死的情况: 经过小主酸菜我,各种方法的尝试后,找到一个初步可以解决的方案,在这里分享给大 ...

  5. 在jQuery ajax中按钮button和submit的区别分析

    在使用jQuery ajax的get方法进行页面传值,不能用submit,否则无刷新获取数据展示 点击submit提交按钮,sendPwd.php通过$_POST接收传过来的值,然后echo一段数据. ...

  6. 制作按钮(Button)

    按钮的核心作用 1.按钮能接收单击并触发响应事件. 2.按钮被单击时能同时触发多个响应事件. 3.按钮可以有普通.悬停.单击.禁用等多个状态的不同表现. 4.广泛的说,按钮的核心在于接收事件,任何可以 ...

  7. 前端表单中有按钮button自动提交表单

    问题描述 在设计表单时,表单内有一个按钮<button>,该按钮是用来获取其他数据或执行其他操作的.并不是让他提交表单. 解决方案 1) 设置 form 的 onsubmit='retur ...

  8. 按钮在执行frame动画的时候怎么响应触发事件?

    按钮在执行frame动画的时候怎么响应触发事件? 代码中效果(请注意,我并没有点击到按钮,而是点击到按钮的终点frame值处): 对应的代码: // // ViewController.m // Ta ...

  9. button 按钮,结合onclick事件,验证和提交表单

    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/ ...

随机推荐

  1. [听点音乐]American Music Awards 2015 Winners

    “see you again” - wiz khalifa feat. charlie puth Lyrics   It's been a long day without you my friend ...

  2. SVN 树冲突的解决方法(Ubuntu 环境)

    今天在 服务器上(Ubuntu) svn up 更新的时候,出现了 SVN 树冲突 root@futongdai:~# cd /home/wwwroot/newcrm.ofim.com/ root@f ...

  3. 为Ubuntu Server安装gnome图形桌面环境

    Ubuntu Server版默认都没有图形桌面(GUI),但是可以安装,以下共有两种安装方法. 一.安装全部Gnome桌面环境 Ubuntu系列桌面实际上有几种桌面应用程序,包括Ubuntu-desk ...

  4. 解决mysql出现“the table is full”的问题

    解决mysql出现“the table is full”的问题 2010-12-20 09:15:17 分类: LINUX 今天中午收到mysql错误日志监控发来的警报,错误日志如下: 101209 ...

  5. RT-Thread信号量的基本操作

    抽象的来讲,信号量的特性如下:信号量是一个非负整数(车位数),所有通过它的线程/进程(车辆)都会将该整数减一(通过它当然是为了使用资源),当该整数值为 0 时,所有试图通过它的线程都将处于等待状态.在 ...

  6. Oracle数据库--SQL

    1.事务(Transaction ) 1)命名事务 set transaction name ‘transaction_name ’; 2)查看事务是否存在 select name from v$tr ...

  7. Subset sum problem

    https://en.wikipedia.org/wiki/Subset_sum_problem In computer science, the subset sum problem is an i ...

  8. include pointers as a primitive data type

    Computer Science An Overview _J. Glenn Brookshear _11th Edition Many modern programming languages in ...

  9. Delphi 指针

    1:指针的赋值. type RTestInfo = record Age:Integer; end; PtestInfo = ^ RtestInfo; var Test1,Test2:PtestInf ...

  10. Bluetooth RFCOMM介绍

    目录 1. 介绍 2. 服务概述 2.1 RS-232控制信号 2.2 Null Modem Emulation 2.3 多串口仿真 3. 服务接口描述 4. RFCOMM帧类型 5. RFCOMM帧 ...