Cocostudio 总结

来源:互联网 发布:关键词排名优化方案 编辑:程序博客网 时间:2024/04/29 19:27

一、控件

控件基类

1
UIWidget:所有UI控件的基类
1
2
3
addChild:添加UIWidget类型的节点
 
addRenderer:添加CCNode类型的节点

所有UIWidget,都可以设置成触摸setTouchEnable(true)

1
2
setTouchEnable(true)
addTouchEventListener(CCObject* target,SEL_TouchEvent selector):设置触摸处理<br>setName:设置名字<br>getRect:获取尺寸

scale9:9宫格相关东西,拼接成大图

1
2
setScale9Enabled(true);
setSize(size);

 

UIButton:

1
2
3
备注:按钮
setPressedActionEnabled:添加按下放大动画
addTouchEventListener(this, toucheventselector(UIButtonTest::touchEvent));

 

UITextButton

1
2
备注:按钮,按钮上面带文字
setText:设置显示内容

 

UICheckBox

1
2
备注:CheckBox,不解释
addEventListenerCheckBox:选择效果变化触发方法

 

UISlider

1
2
3
4
5
6
备注:滑动条
loadBarTexture:设置背景长条纹理
loadSlidBallTextures:设置滚球纹理
loadProgressBarTexture:设置进度条纹理
addEventListenerSlider:进度变化调用,getPercent获取值(0~100)
setCapInsets(CCRectMake(0, 0, 0, 0));被设置scale9时,需要调用

 

UILoadingBar

1
2
3
4
5
备注:进度条,与滑动条的区别在于没有滑动按钮
setTexture:设置纹理
setPercent:设置进程(0~100)
setDirection(LoadingBarTypeRight):默认从左到右
setCapInsets(CCRectMake(0, 0, 0, 0));被设置scale9时,需要调用

 

UILabelAtlas

1
2
备注:图片文字控件
setProperty("1234567890","cocosgui/labelatlas.png", 17, 22, "0")

 

UITextArea

1
2
3
4
备注:文字区域控件,显示大段换行文字
setTextAreaSize:设置显示区域
setTextHorizontalAlignment(kCCTextAlignmentCenter):设置显示模式
setText:设置内容

 

UITextField

1
2
3
4
5
6
7
备注:输入法控件
setPlaceHolder:设置无内容时的显示
addEventListenerTextField:设置回调
setMaxLengthEnable:字数限制开关
setMaxLength:字数限制个数
setPasswordEnable:密码模式开关
setPasswordStyleText(“*”):密码显示替代符

 

UILayout(panel)

1
2
3
4
5
6
7
8
9
10
11
12
13
14
备注:容器
setSize:大小
setBackGroundColorType:抹色类型(支持均匀、梯度)
setBackGroundColor:抹色的色值
setClippingEnabled:图片背景开关
setBackGroundImage:图片
setBackGroundImageScale9Enabled:9碎片拼接开关
setBackGroundImage:9碎片纹理
setLayoutType(LAYOUT_LINEAR_VERTICAL);设置陈立方式
//陈立参数
UILinearLayoutParameter* lp1 = UILinearLayoutParameter::create();
button->setLayoutParameter(lp1);
lp1->setGravity(LINEAR_GRAVITY_CENTER_HORIZONTAL);
lp1->setMargin(UIMargin(0, 5, 0, 10));

 

UIScrollView

1
2
3
4
5
备注:滚动容器(任意UIWidget类型)它以左上角为锚点
setBounceEnabled:弹跳开关,拉过了之后,可以弹回来
setInnerContainerSize:设置内部实际大小,必须大于等于size
setDirection(SCROLLVIEW_DIR_HORIZONTAL):设置滚动方向
addChild:UIWidget都可以

 

UIPageView

1
2
3
4
5
6
备注:翻页容器(必须UILayout)
addPage:添加UILayout对象
getPage:获取当前页数
addEventListenerPageView:回调方法
case PAGEVIEW_EVENT_TURNING:
UIPageView* pageView = dynamic_cast<UIPageView*>(pSender);

 

UIListView

1
2
3
4
5
6
7
8
9
10
11
备注:同UIScrollView(只能UILayout)
setDirection(LISTVIEW_DIR_HORIZONTAL);:朝向
setBackGroundImageScale9Enabled:背景
setBackGroundImage:背景
addEventListenerListView:回调方法(完成初始化时,list发生变化时)
initChildWithDataLength:设置数据个数
addChild:只能添加UILayout类型
getUpdateDataIndex:获取更新的索引值
getUpdateChild:获取更新项
setUpdateSuccess:设置更新状态
(不用设置listView内数据的总尺寸大小)

 

UIDragPanel

1
2
3
4
5
6
备注:拖拽容器(任意UIWidget)
setBackGroundImageScale9Enabled
setBackGroundImage
setBounceEnabled:弹跳开关,拉过了之后,可以弹回来
setSize:设计显示大小
setInnerContainerSize:设置实际大小

 

UINodeContainer

1
2
3
备注:CCNode容器,与CCNode挂钩
addCCNode:添加各种CCNode,如CCSprite
addRenderer:也可以添加CCNode,每个UIWidget拥有

 

二、程序使用

1
2
3
4
//UI层创建
UILayer* ul = UILayer::create();
UILayout* widget = dynamic_cast<UILayout*>(GUIReader::shareReader()->widgetFromJsonFile("ui_file/gameInfo_1.json"));
Ul->addWidget(widget);

 

1
2
//获取
UIImageView * lifeBar = (UIImageView *)ul->getWidgetByName("lifeBar");

 

1
2
3
4
5
//释放
onExit或析构中需调用(否则内存泄露)
GUIReader::shareReader()->purgeGUIReader();
DictionaryHelper::shareHelper()->purgeDictionaryHelper();
ActionManager::shareManager()->purgeActionManager();
0 0
原创粉丝点击