cocos2d-html5 简易 下拉表单 控件
生活随笔
收集整理的這篇文章主要介紹了
cocos2d-html5 简易 下拉表单 控件
小編覺得挺不錯的,現(xiàn)在分享給大家,幫大家做個參考.
剛才在CH5的群里問了問 ?有沒有大俠寫過 下拉表單控件啊! ?沒人鳥窩 ,DZ老師表示非常傷心啊 ?,于是乎 ?自己寫一個把 共享給大家。
效果圖上一個 ?僅僅實現(xiàn)了一個最最主要的控件 ?非常easy ?別吐槽啊,以后有空我會完好一下的,假設(shè)有朋友自愿幫忙完好一下就更好了。
有不論什么問題請加DZ老師的QQ 460418221
引擎版本號 : 2.2.2
原理:有空再寫吧 ??
源代碼:
/*** Created with JetBrains WebStorm.* User: Dz_Yang* Date: 14-4-29* Time: 上午13:19* To change this template use File | Settings | File Templates.*/var Pull_down_menu = cc.Layer.extend({WIDTH:0,HEIGHT:0,COLOR:null,STR_ARRAY:null,SElECTS:null,SELECTING_ID:null,STATE:0,init:function(){this._super();var winsize = cc.Director.getInstance().getWinSize();this.SElECTS = new Array();for(var i=0;i<this.STR_ARRAY.length;i++){this.SElECTS[i] = cc.LayerColor.create(this.COLOR, this.WIDTH, this.HEIGHT);var txt = cc.LabelTTF.create(this.STR_ARRAY[i],"Arial",this.HEIGHT * 2/3);txt.setPosition(cc.p(this.WIDTH/2,this.HEIGHT/2));this.SElECTS[i].addChild(txt);this.SElECTS[i].setAnchorPoint(cc.p(0,1));this.SElECTS[i].setPosition(cc.p(0,0-(i+1)*this.HEIGHT));this.addChild(this.SElECTS[i]);}this.choose(0);this.setTouchEnabled(true);return true;},onTouchesBegan:function (touches, event){if(touches.length == 1){var click_id = null;for(var i=0;i<this.SElECTS.length;i++){if(cc.rectContainsPoint(this.SElECTS[i].getBoundingBox(),cc.p( touches[0].getLocation().x -this.getPositionX() , touches[0].getLocation().y -this.getPositionY()) )){click_id = i;break;} else{}}if(click_id != null){if(this.STATE == 0){if(click_id == this.SELECTING_ID){this.open();}}else if(this.STATE == 1){this.choose(click_id);}}}},onTouchesMoved:function (touches, event){},onTouchesEnded:function (touches, event){},draw:function(){cc.drawingUtil.setDrawColor4B(255, 255, 255, 255);cc.drawingUtil.setLineWidth(3);cc.drawingUtil.drawLine(cc.p(0,0),cc.p(this.WIDTH,0));cc.drawingUtil.drawLine(cc.p(0,0),cc.p(0,this.HEIGHT));cc.drawingUtil.drawLine(cc.p(0,this.HEIGHT),cc.p(this.WIDTH,this.HEIGHT));cc.drawingUtil.drawLine(cc.p(this.WIDTH,this.HEIGHT),cc.p(this.WIDTH,0));},open:function(){this.STATE =1;for(var i=0;i<this.SElECTS.length;i++){this.SElECTS[i].setPosition(cc.p(0,0-(i+1)*this.HEIGHT));this.SElECTS[i].setVisible(true);}},close:function(){this.STATE =0;for(var i=0;i<this.SElECTS.length;i++){this.SElECTS[i].setVisible(false);}},choose:function(id){this.SELECTING_ID = id;this.close();this.SElECTS[id].setVisible(true);this.SElECTS[id].setPosition(cc.p(0,0));},getSelectedID:function(){return this.SELECTING_ID;}});Pull_down_menu.create = function(color, width, height, str_array){var re = new Pull_down_menu();re.WIDTH = width;re.HEIGHT = height;re.COLOR = color;re.STR_ARRAY = str_array;re.init();return re;};用法:
var pdm = Pull_down_menu.create(cc.c4(100,100,100,255),70,20,["丁丁","拉拉","迪西","小波"]);//第一個選項是底色,第二個是寬 第三個高 最后是一個字符串?dāng)?shù)組pdm.setPosition(cc.p(170,winsize.height-150));this.addChild(pdm);//是用pdm.getSelectedID() 能夠獲取選擇的選項卡的下標(biāo)歡迎轉(zhuǎn)載,請標(biāo)明原帖地址:http://blog.csdn.net/ycd_harry/article/details/24709603
轉(zhuǎn)載于:https://www.cnblogs.com/hrhguanli/p/3912228.html
總結(jié)
以上是生活随笔為你收集整理的cocos2d-html5 简易 下拉表单 控件的全部內(nèi)容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: Linux MTD系统剖析
- 下一篇: 关于CacheLookup一个有趣的问题