cocos -js 实现计算器功能
来源:互联网 发布:雅思听力技巧 知乎 编辑:程序博客网 时间:2024/06/14 01:46
var HelloWorldLayer = cc.Layer.extend({ _mainUI:null, _lab:null, TOTAL:18, //输入的数 _tempValue: null, //第一个输入的数 _firstDate: null, //第二个输入的数 _secondDate: null, //运算符 _tempType:null, ctor:function () { this._super(); this._init(); }, _init:function(){ this._tempValue=""; this._mainUI =ccs.load(res.main_json).node; this.addChild(this._mainUI); this._lab=ccui.helper.seekWidgetByName(this._mainUI,"result_lab"); //设置文本内容 this._addEvent(); }, //添加按钮点击事件 _addEvent:function(){ var btn; for(var i=0;i<this.TOTAL;i++){ btn=this._getWidgetByName(this._mainUI,"btn_"+i); btn.addTouchEventListener(this._inputHandler.bind(this),this._mainUI); } }, //点击按钮的回调方法 _inputHandler:function(sender,type){ if(type == ccui.Widget.TOUCH_ENDED){ var str =sender.name.split("btn_")[1]; if(str<= 10)this._checkInput(str); else if(str == 11) this._checkResult(); else if(str <= 15) this._checkCreactor(str); else if(str == 17) this._clearShow(); } }, /*检查输入结果*/ _checkResult:function(){ this._secondDate=parseFloat(this._getLabString()); this._tempValue = ""; switch ( this._tempType){ case "12": this._firstDate += this._secondDate; break; case "13": this._firstDate -= this._secondDate; break; case "14": this._firstDate *= this._secondDate; break; case "15": this._firstDate /= this._secondDate; break; } this._setLabString(this._firstDate); }, /**检查运算符*/ _checkCreactor:function(str){ this._firstDate= parseFloat(this._getLabString()); this._tempType= str; this._tempValue = ""; }, _checkInput:function(value){ var str = value; if(this._getLabString()=="0"){ if(value == 10) this._tempValue = "0."; else this._tempValue = str; }else { if (value == 10) str = (this._tempValue.indexOf(".") >= 0 ? "" : "."); this._tempValue += str; } this._setLabString(this._tempValue); }, //清除显示 _clearShow:function(){ this._tempValue = ""; this._setLabString("0"); }, //设置文本内容 _setLabString:function(str){ this._lab.setString(str); }, _getLabString: function(){ return this._lab.getString() }, _getWidgetByName:function(par,name){ return ccui.helper.seekWidgetByName(par,name); },}); //获取对象 getWidgetByname =function(par,name){ return ccui.helper.seekWidgetByName(par.name);}, //获取加载外部节点 getWidgetByname =function(source){ return ccs.load(source).node; };var HelloWorldScene = cc.Scene.extend({ onEnter:function () { this._super(); var layer = new HelloWorldLayer(); this.addChild(layer); }});
0 0
- cocos -js 实现计算器功能
- js实现简易计算器功能
- 使用 js 实现 贷款计算器功能
- html+js+css实现计算器功能
- cocos-js (web端)输入框功能实现
- 网页版计算器的实现(js实现计算功能)
- 计算器功能简单实现
- Android实现计算器功能
- 实现计算器功能
- android实现计算器功能
- UI04 实现计算器功能
- 计算器功能实现
- JavaScript实现计算器功能
- 简单计算器-功能实现
- Python---计算器功能实现
- 简单计算器功能实现
- javascript实现计算器功能
- JS实现科学计算器
- DOCKER学习之(二) 容器部分常用命令
- 【笔记】《内核剖析》-01-概述
- 《剑指offer》二叉树中和为某一值的路径
- localStorage的高级操作写法
- AndroidStudio 与Eclipse快捷键对比
- cocos -js 实现计算器功能
- caffe interface --- python
- 今日学习
- 职业发展
- 打击破解软件,终于有解决良方了!
- PBR贴图转换1——对PBR的误解
- 2016 Multi-University Training Contest 1 1001 hdu 5723 DFS+并查集最小生树
- 上code之前的test plan
- HDU 5723 Abandoned country (最小生成树+树形dp)