cocos代码研究(16)Widget子类RadioButton学习笔记
2015-10-08 16:25
429 查看
理论基础
RadioButton是一种特定类型的两状态按钮,它与复选框相似。它可以 和RadioButtonGroup一起使用,形成一个"组"。继承自AbstractCheckButton,AbstractCheckButton继承自Widget。代码部分
void addEventListener (const ccRadioButtonCallback &callback)注册一个回调函数, 它将在单选按钮被选中或者取消的时候被调用.
bool isSelected () const
查询是否选中复选框。
void setSelected (bool selected)
修改复选框的状态 设置True会使复选框变为“选中状态”,否则传False会使复选框变为“未选中状态”
void loadTextures (const std::string &background, //背景普通状态图片的名字。
const std::string &backgroundSelected, //背景选择状态图片的名字。
const std::string &cross, //勾选选中状态图片的名字。
const std::string &backgroundDisabled, //背景禁用状态图片名字。
const std::string &frontCrossDisabled, //勾选禁用状态图片名字。
TextureResType texType=TextureResType::LOCAL) //
加载所有纹理并初始化一个复选框。
void loadTextureBackGround (const std::string &backGround, TextureResType type=TextureResType::LOCAL)
加载背景普通状态纹理
void loadTextureBackGroundSelected (const std::string &backGroundSelected, TextureResType texType=TextureResType::LOCAL)
加载背景选中状态纹理的图片
void loadTextureFrontCross (const std::string &crossTextureName, TextureResType texType=TextureResType::LOCAL)
加载勾选选中状态的纹理图片
void loadTextureBackGroundDisabled (const std::string &backGroundDisabled, TextureResType texType=TextureResType::LOCAL)
加载背景禁用状态纹理的图片
void loadTextureFrontCrossDisabled (const std::string &frontCrossDisabled, TextureResType texType=TextureResType::LOCAL)
加载勾选禁用状态的纹理图片
virtual Size getVirtualRendererSize () const override
获取虚拟渲染节点的尺寸
virtual Node * getVirtualRenderer () override
控件的内部渲染节点。 例如,一个按钮的虚拟渲染节点是它的纹理节点。
void setZoomScale (float scale)
当用户按下复选框时,按钮将会缩放到一个比例 最后复选框的缩放值等于(复选框原尺寸+ _zoomScale)
float getZoomScale () const
返回一个缩放比例
Sprite * getRendererBackground () const
返回背景普通状态的渲染节点
Sprite * getRendererBackgroundSelected () const
返回背景选择状态的渲染节点
Sprite * getRendererFrontCross () const
返回前景普通状态的渲染节点
Sprite * getRendererBackgroundDisabled () const
返回背景禁用状态的渲染节点
Sprite * getRendererFrontCrossDisabled () const
返回前景禁用状态的渲染节点
实例:
Size widgetSize = _widget->getContentSize(); // Create a radio button group _radioButtonGroup = RadioButtonGroup::create(); _uiLayer->addChild(_radioButtonGroup); // Create the radio buttons static const int NUMBER_OF_BUTTONS = 5; startPosX = widgetSize.width / 2.0f - ((NUMBER_OF_BUTTONS - 1) / 2.0f) * BUTTON_WIDTH; for(int i = 0; i < NUMBER_OF_BUTTONS; ++i) { RadioButton* radioButton = RadioButton::create("cocosui/radio_button_off.png", "cocosui/radio_button_on.png"); float posX = startPosX + BUTTON_WIDTH * i; radioButton->setPosition(Vec2(posX, widgetSize.height / 2.0f + 10)); radioButton->setScale(1.2f); _radioButtonGroup->addRadioButton(radioButton); _uiLayer->addChild(radioButton); }
相关文章推荐
- cocos2d-x中false,setSwallowTouches,stopPropagation的区别
- cocos2d-x 离线帮助文档,doxygen的使用步骤
- Cocos2dx杂记
- 给新建的Cocos2d-x 3.0rc0 的Win32工程添加CocoStudio库
- cocos代码研究(15)Widget子类CheckBox学习笔记
- 初学cocos2dx lua 最基本的知识
- Cocos2D的平台检查宏
- Cocos2D的平台检查宏
- Cocos2D的平台检查宏
- Android和iOS中Cocos2D日志为什么会出现skip frames
- Android和iOS中Cocos2D日志为什么会出现skip frames
- Android和iOS中Cocos2D日志为什么会出现skip frames
- cocos2dx绑定lua并进行代码测试
- cocos2dx-lua v3 -sprit 精灵详解
- 移植Cocos2D到Android平台的原理
- 移植Cocos2D到Android平台的原理
- 移植Cocos2D到Android平台的原理
- cocos 游戏移植到 Windows10 之路 -- 环境搭建
- 火云开发课堂 - 《Shader从入门到精通》系列 第十五节:在Shader中对3D模型进行颜色设置
- 寒風的Cocos之旅之C++篇---drawNode用法