cc.Button
cc.Button
1:添加按钮的方法
(1)直接创建带Button组件的节点;
(2)先创建节点,再添加组件;
2:按钮组件, 按钮是游戏中最常用的组件, 点击然后响应事件;
3: 按钮的过渡效果:
过渡: 普通状态, 鼠标滑动到物体上, 按下状态, 禁用状态
(1)没有过渡,只有响应事件;
(2)颜色过渡, 过渡效果中使用颜色;
(3)精灵过渡,使用图片过渡;
(4)缩放过渡, 选项,在disable的时候是否置灰;
4: 按钮禁用;
5: 按钮添加响应事件 --> 节点-->组件 --> 代码的函数;
6: 按钮传递自定义参数; ---> 字符串对象;
7: Button响应这个触摸点击,所以Button所挂的这个节点,一定要有大小,如果你向大小(0, 0)的节点上,挂一个Button,这个是无法响应点击事件;
代码使用cc.Button
1: 代码添加/获取cc.Button组件;
2: 代码里面添加按钮的响应事件;
3: 代码触发按钮指定的回掉函数;
4: Component.EventHandler
var eventHandler = new cc.Component.EventHandler();
eventHandler.target = newTarget;
eventHandler.component = "MainMenu";
eventHandler.handler = "OnClick";
eventHandler.customEventData = "my data";
eventHandler.emit(["param1", "param2", ....]);
// use this for initialization
onLoad: function () {
// 获取button组件
this.start_button = this.node.getChildByName("ks_up").getComponent(cc.Button); // 添加button组件
this.red_button = this.node.getChildByName("red_button").addComponent(cc.Button);
// 添加一个响应函数
var click_event = new cc.Component.EventHandler();
click_event.target = this.node;
click_event.component = "game_scene";
click_event.handler = "on_red_button_click";
click_event.customEventData = "red_button_data_77777";
// this.red_button.clickEvents = [click_event];
this.red_button.clickEvents.push(click_event); // end // 代码触发按钮的响应事件,而不用自己去触摸
this.scheduleOnce(function() {
var click_events = this.red_button.clickEvents;
for(var i = 0; i < click_events.length; i ++) {
var comp_env_handle = click_events[i];
// 在代码里面触发按钮的响应函数
comp_env_handle.emit(["", "red_button_data_6666"]);
}
}.bind(this), 3);
// end
}, on_red_button_click: function(e, custom) {
console.log("on_red_button_click: ", custom);
},
// 关卡按钮1-10, 第几关
// e 本次触摸的触摸事件
// customEventData is String;
on_button_click: function(e, level) {
//level = parseInt(level);
console.log("on_button_click called:", level);
},
btn1_click: function () {
console.log("this is button click ");
},
cc.Button的更多相关文章
- Cocos Creator cc.Button (脚本事件内容)
cc.Class({extends: cc.Component,properties: {}, onLoad: function () { var clickEventHandler = new cc ...
- cc.Lable组件,RichText组件,AudioSouce组件的使用
一.cc.Lable组件的使用 1.创建Label的方法 a.通过菜单直接创建Label组件:b.先创建节点,然后在节点上绑定Label组件即可. 2.Label 面板上的属性 String => ...
- Sprite组件和Button组件的使用
一.Sprint组件的使用 1.游戏中显示一张图片,通常我们称之为"精灵" sprite 2.cocos creator如果需要显示一个图片,那么需要在节点上挂一个精灵组件,为这个 ...
- 获取Button脚本挂载的事件名
(function(){ var Super = function(){}; Super.prototype = cc.Button.prototype; //实例化原型 Super.prototyp ...
- cocos creator 重写源码按钮Button点击音频封装
(function(){ var Super = function(){}; Super.prototype = cc.Button.prototype; //实例化原型 Super.prototyp ...
- Cocos Creator 为Button添加事件的两种方法
Button添加事件 Button 目前只支持 Click 事件,即当用户点击并释放 Button 时才会触发相应的回调函数.通过脚本代码添加回调方法一这种方法添加的事件回调和使用编辑器添加的事件回调 ...
- cc.Component
组件入口函数1: onLoad: 组件加载的时候调用, 保证了你可以获取到场景中的其他节点,以及节点关联的资源数据;2: start: 也就是第一次执行 update 之前触发;3: update(d ...
- UI 组件 | Button
最近在与其他自学 Cocos Creator 的小伙伴们交流过程中,发现许多小伙伴对基础组件的应用并不是特别了解,自己在编写游戏的过程中也经常对某个属性或者方法的用法所困扰,而网上也没有比较清晰的用法 ...
- iOS 根据字符串来定位地址
- (void)viewDidLoad { [super viewDidLoad]; self.geocoder = [[CLGeocoder alloc]init]; // 设置地图可缩放 self ...
随机推荐
- centos6中office及中文输入法安装 (转载)
原创作品,允许转载,转载时请务必以超链接形式标明文章 原始出处 .作者信息和本声明.否则将追究法律责任.http://xuxuezhe.blog.51cto.com/1636138/73 ...
- angularJs 之deferred
angularJs 对promise的封装 var deferred = $q.defer(); deferred.promise.then(function(){ var result = {} c ...
- 【插件开发】—— 13 GEF双击模型事件
前文回顾: 1 插件学习篇 2 简单的建立插件工程以及模型文件分析 3 利用扩展点,开发透视图 4 SWT编程须知 5 SWT简单控件的使用与布局搭配 6 SWT复杂空间与布局搭配 7 SWT布局详解 ...
- _bzoj3223 Tyvj 1729 文艺平衡树【Splay】
传送门:http://www.lydsy.com/JudgeOnline/problem.php?id=3223 裸的,打个标记. #include <cstdio> #include & ...
- bzoj1415 [Noi2005]聪聪和可可【概率dp 数学期望】
传送门:http://www.lydsy.com/JudgeOnline/problem.php?id=1415 noip2016 D1T3,多么痛的领悟...看来要恶补一下与期望相关的东西了. 这是 ...
- 题解报告:hdu 2062 Subset sequence
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=2062 Problem Description 考虑集合An = {1,2,...,n}. 例如,A1 ...
- http缓存之lastModified和etag
1.cache-control 访问资源 首次访问页面时间:2018.2.1 9:56 (当前时间=GMT时间+8h) 缓存时长max-age:1 day Expire缓存失效时间:2018.2. ...
- 08 H5新增input元素
<!doctype html> <html> <head> <meta charset="utf-8"> <title> ...
- css超出部分显示省略号
单行文本 <!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF- ...
- hihocoder offer收割编程练习赛12 B 一面砖墙
思路: 就是求哪个长度出现的次数最多. 实现: #include <iostream> #include <cstdio> #include <algorithm> ...