cocostudio——js 3 final控件事件

前端之家收集整理的这篇文章主要介绍了cocostudio——js 3 final控件事件前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。


http://www.2cto.com/kf/201410/346470.html

最近试用了下cocos ide,然后引擎用的cocos2dx js 3 final,需要build runtime一下,下面是cocos studio相关的一些事件:

添加事件侦听:

?
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
// 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( .backEvent, );
var button = ccui.helper.seekWidgetByName(root,monospace!important; font-size:1em!important; min-height:inherit!important; color:blue!important; background:none!important">"Button_123" );
button.addTouchEventListener( .touchEvent,monospace!important; font-size:1em!important; min-height:inherit!important; background:none!important">);
var title_button = ccui.helper.seekWidgetByName(root,monospace!important; font-size:1em!important; min-height:inherit!important; color:blue!important; background:none!important">"Button_126" );
title_button.addTouchEventListener( );
var scale9_button = ccui.helper.seekWidgetByName(root,monospace!important; font-size:1em!important; min-height:inherit!important; color:blue!important; background:none!important">"Button_129" );
scale9_button.addTouchEventListener( );
// check Box
"res/UICheckBox_Editor/ui_checkBox_editor_1.json" );
.addChild(root);
var checkBox = ccui.helper.seekWidgetByName(root,monospace!important; font-size:1em!important; min-height:inherit!important; color:blue!important; background:none!important">"CheckBox_540" );
cc.log(checkBox.addEventListener);
checkBox.addEventListener( .selectedStateEvent,monospace!important; font-size:1em!important; min-height:inherit!important; background:none!important">);
// 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 ]);
.addChild(root);
var listView = ccui.helper.seekWidgetByName(root,monospace!important; font-size:1em!important; min-height:inherit!important; color:blue!important; background:none!important">"ListView_1214" );
listView.addEventListener( .selectedItemEvent,monospace!important; font-size:1em!important; min-height:inherit!important; background:none!important">);
// page view
"res/UIPageView_Editor/ui_pageview_editor_1.json" );
.addChild(root);
var pageView =ccui.helper.seekWidgetByName(root,monospace!important; font-size:1em!important; min-height:inherit!important; color:blue!important; background:none!important">"PageView_1269" );
pageView.addEventListener( .pageViewEvent,monospace!important; font-size:1em!important; min-height:inherit!important; background:none!important">);
// RichText
var richText = ccui.RichText.create();
richText.ignoreContentAdaptWithSize( false );
richText.setContentSize(cc.size( 120 100 ));
var re1 = ccui.RichElementText.create( 1 255 "This color is white. " "Helvetica" 10 );
var re2 = ccui.RichElementText.create( 2 "And this is yellow. " );
var re3 = ccui.RichElementText.create( 3 "This one is blue. " );
var re4 = ccui.RichElementText.create( 4 "And green. " );
var re5 = ccui.RichElementText.create( 5 "Last one is red " );
var re6 = ccui.RichElementText.create( 7 "Have fun!! " );
richText.pushBackElement(re1);
@H_482_502@ richText.insertElement(re2,monospace!important; font-size:1em!important; min-height:inherit!important; background:none!important">);
richText.pushBackElement(re3);
richText.pushBackElement(re4);
richText.pushBackElement(re5);
richText.pushBackElement(re6);
richText.setPosition(cc.p( 1280 / 720 ));
.addChild(richText);
// slider
"res/UiSlider_Editor/ui_slider_editor_1.json" );
.addChild(root);
var slider = ccui.helper.seekWidgetByName(root,monospace!important; font-size:1em!important; min-height:inherit!important; color:blue!important; background:none!important">"Slider_738" );
slider.addEventListener( .sliderEvent,monospace!important; font-size:1em!important; min-height:inherit!important; background:none!important">);
var scale9_slider = ccui.helper.seekWidgetByName(root,monospace!important; font-size:1em!important; min-height:inherit!important; color:blue!important; background:none!important">"Slider_740" );
scale9_slider.addEventListener( );
// text field
"res/UITextField_Editor/ui_textfield_editor_1.json" );
.addChild(root);
var textField_normal = ccui.helper.seekWidgetByName(root,monospace!important; font-size:1em!important; min-height:inherit!important; color:blue!important; background:none!important">"TextField_1109" );
textField_normal.addEventListener( .textFieldEvent,monospace!important; font-size:1em!important; min-height:inherit!important; background:none!important">);
var textField_max_character = ccui.helper.seekWidgetByName(root,monospace!important; font-size:1em!important; min-height:inherit!important; color:blue!important; background:none!important">"TextField_1110" );
textField_max_character.addEventListener( );
var textField_password = ccui.helper.seekWidgetByName(root,monospace!important; font-size:1em!important; min-height:inherit!important; color:blue!important; background:none!important">"TextField_1107" );
textField_password.addEventListener( );

各个事件回调:

?
86
87
88
89
90
91
92
93
94
95
96
// widget
touchEvent: function (sender,type) {
switch (type) {
case ccui.Widget.TOUCH_BEGAN:
cc.log( "Touch Down" );
break ;
ccui.Widget.TOUCH_MOVED:
"Touch Move" );
;
ccui.Widget.TOUCH_ENDED:
"Touch Up" );
;
ccui.Widget.TOUCH_CANCELED:
"Touch Cancelled" );
;
default :
;
}
},
// check Box
selectedStateEvent: function (sender,type) {
(type) {
ccui.CheckBox.EVENT_SELECTED:
"Selected" );
;
ccui.CheckBox.EVENT_UNSELECTED:
"Unselected" );
;
:
;
}
// list view
selectedItemEvent: function (sender,type) {
(type) {
ccui.ListView.EVENT_SELECTED_ITEM:
var listViewEx = sender;
"select child index = " + listViewEx.getCurSelectedIndex());
;
:
;
}
// page view
pageViewEvent: function (sender,type) {
(type) {
@H_482_502@ ccui.PageView.EVENT_TURNING:
var pageView = sender;
"page = " + (pageView.getCurPageIndex() + ));
;
:
;
}
// slider
sliderEvent: function (sender,type) {
(type) {
ccui.Slider.EVENT_PERCENT_CHANGED:
var slider = sender;
var percent = slider.getPercent();
"Percent " + percent.toFixed( ));
;
:
;
}
// text field
textFieldEvent: function (sender,type) {
(type) {
ccui.TextField. EVENT_ATTACH_WITH_IME:
"attach with IME" );
;
ccui.TextField. EVENT_DETACH_WITH_IME:
"detach with IME" );
;
ccui.TextField. EVENT_INSERT_TEXT:
"insert words" );
;
ccui.TextField. EVENT_DELETE_BACKWARD:
"delete word" );
;
@H_404_1079@ :
;
}
}

猜你在找的Cocos2d-x相关文章