码迷,mamicode.com
首页 > Web开发 > 详细

cocostudio——js 3 final控件事件

时间:2014-10-25 23:05:15      阅读:517      评论:0      收藏:0      [点我收藏+]

标签:blog   color   io   os   ar   java   sp   on   2014   

  最近试用了下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控件事件

标签:blog   color   io   os   ar   java   sp   on   2014   

原文地址:http://blog.csdn.net/adfansong/article/details/40457585

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!