zoukankan      html  css  js  c++  java
  • 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;
        	}
        }



  • 相关阅读:
    [BZOJ2127]happiness(最小割)
    [网络流24题]餐巾计划问题(费用流/有上下界的费用流)
    SQL注入-数据库判断
    Web渗透实验:基于Weblogic的一系列漏洞
    使用nmap 验证多种漏洞
    smb(ms17-010)远程命令执行之msf
    ashx后门
    Windows Server 2008 R2入门之用户管理
    windows2008,命令行远程登录
    利用jspx解决jsp后缀被限制拿shell
  • 原文地址:https://www.cnblogs.com/zfyouxi/p/4231795.html
Copyright © 2011-2022 走看看