首页 > 代码库 > cocostudio——js 3 final控件事件
cocostudio——js 3 final控件事件
最近试用了下cocos ide,然后引擎用的cocos2dx js 3 final,需要build runtime一下,下面是cocos studio相关的一些事件:
添加事件侦听:
// button var root = ccs.uiReader.widgetFromJsonFile("res/UIButton_Editor/UIButton_Editor_1.json"); this.addChild(root); var back_label = ccui.helper.seekWidgetByName(root, "back"); back_label.addTouchEventListener(this.backEvent,this); var button = ccui.helper.seekWidgetByName(root, "Button_123"); button.addTouchEventListener(this.touchEvent,this); var title_button = ccui.helper.seekWidgetByName(root, "Button_126"); title_button.addTouchEventListener(this.touchEvent,this); var scale9_button = ccui.helper.seekWidgetByName(root, "Button_129"); scale9_button.addTouchEventListener(this.touchEvent,this); // check box var root = ccs.uiReader.widgetFromJsonFile("res/UICheckBox_Editor/ui_checkbox_editor_1.json"); this.addChild(root); var checkbox = ccui.helper.seekWidgetByName(root, "CheckBox_540"); cc.log(checkbox.addEventListener); checkbox.addEventListener(this.selectedStateEvent,this); // list view var LISTVIEW_RES = [ "res/UIListView_Editor/UIListView_Vertical_Editor/ui_listview_editor_1.json", "res/UIListView_Editor/UIListView_Horizontal_Editor/ui_listview_horizontal_editor_1.json" ]; var root = ccs.uiReader.widgetFromJsonFile(LISTVIEW_RES[0]); this.addChild(root); var listView = ccui.helper.seekWidgetByName(root, "ListView_1214"); listView.addEventListener(this.selectedItemEvent,this); // page view var root = ccs.uiReader.widgetFromJsonFile("res/UIPageView_Editor/ui_pageview_editor_1.json"); this.addChild(root); var pageView =ccui.helper.seekWidgetByName(root, "PageView_1269"); pageView.addEventListener(this.pageViewEvent, this); // RichText var richText = ccui.RichText.create(); richText.ignoreContentAdaptWithSize(false); richText.setContentSize(cc.size(120, 100)); var re1 = ccui.RichElementText.create(1, cc.color.WHITE, 255, "This color is white. ", "Helvetica", 10); var re2 = ccui.RichElementText.create(2, cc.color.YELLOW, 255, "And this is yellow. ", "Helvetica", 10); var re3 = ccui.RichElementText.create(3, cc.color.BLUE, 255, "This one is blue. ", "Helvetica", 10); var re4 = ccui.RichElementText.create(4, cc.color.GREEN, 255, "And green. ", "Helvetica", 10); var re5 = ccui.RichElementText.create(5, cc.color.RED, 255, "Last one is red ", "Helvetica", 10); var re6 = ccui.RichElementText.create(7, cc.color.ORANGE, 255, "Have fun!! ", "Helvetica", 10); richText.pushBackElement(re1); richText.insertElement(re2, 1); richText.pushBackElement(re3); richText.pushBackElement(re4); richText.pushBackElement(re5); richText.pushBackElement(re6); richText.setPosition(cc.p(1280 / 2, 720 / 2)); this.addChild(richText); // slider var root = ccs.uiReader.widgetFromJsonFile("res/UISlider_Editor/ui_slider_editor_1.json"); this.addChild(root); var slider = ccui.helper.seekWidgetByName(root, "Slider_738"); slider.addEventListener(this.sliderEvent,this); var scale9_slider = ccui.helper.seekWidgetByName(root, "Slider_740"); scale9_slider.addEventListener(this.sliderEvent,this); // text field var root = ccs.uiReader.widgetFromJsonFile("res/UITextField_Editor/ui_textfield_editor_1.json"); this.addChild(root); var textField_normal = ccui.helper.seekWidgetByName(root, "TextField_1109"); textField_normal.addEventListener(this.textFieldEvent,this); var textField_max_character = ccui.helper.seekWidgetByName(root, "TextField_1110"); textField_max_character.addEventListener(this.textFieldEvent,this); var textField_password = ccui.helper.seekWidgetByName(root, "TextField_1107"); textField_password.addEventListener(this.textFieldEvent,this);
各个事件回调:
// widget touchEvent: function (sender, type) { switch (type) { case ccui.Widget.TOUCH_BEGAN: cc.log("Touch Down"); break; case ccui.Widget.TOUCH_MOVED: cc.log("Touch Move"); break; case ccui.Widget.TOUCH_ENDED: cc.log("Touch Up"); break; case ccui.Widget.TOUCH_CANCELED: cc.log("Touch Cancelled"); break; default: break; } }, // check box selectedStateEvent: function (sender, type) { switch (type) { case ccui.CheckBox.EVENT_SELECTED: cc.log("Selected"); break; case ccui.CheckBox.EVENT_UNSELECTED: cc.log("Unselected"); break; default: break; } }, // list view selectedItemEvent: function (sender, type) { switch (type) { case ccui.ListView.EVENT_SELECTED_ITEM: var listViewEx = sender; cc.log("select child index = " + listViewEx.getCurSelectedIndex()); break; default: break; } }, // page view pageViewEvent: function (sender, type) { switch (type) { case ccui.PageView.EVENT_TURNING: var pageView = sender; cc.log("page = " + (pageView.getCurPageIndex() + 1)); break; default: break; } }, // slider sliderEvent: function (sender, type) { switch (type) { case ccui.Slider.EVENT_PERCENT_CHANGED: var slider = sender; var percent = slider.getPercent(); cc.log("Percent " + percent.toFixed(0)); break; default: break; } }, // text field textFieldEvent: function (sender, type) { switch (type) { case ccui.TextField. EVENT_ATTACH_WITH_IME: cc.log("attach with IME"); break; case ccui.TextField. EVENT_DETACH_WITH_IME: cc.log("detach with IME"); break; case ccui.TextField. EVENT_INSERT_TEXT: cc.log("insert words"); break; case ccui.TextField. EVENT_DELETE_BACKWARD: cc.log("delete word"); break; default: break; } }
cocostudio——js 3 final控件事件
声明:以上内容来自用户投稿及互联网公开渠道收集整理发布,本网站不拥有所有权,未作人工编辑处理,也不承担相关法律责任,若内容有误或涉及侵权可进行投诉: 投诉/举报 工作人员会在5个工作日内联系你,一经查实,本站将立刻删除涉嫌侵权内容。