文章中心 -> 软件使用

文章正文

 青瓷引擎UI组件怎么用之开关和开关组,主要从Toggle、ToggleGroup两方面讲述,由绿盟小编精心整理,希望能够对您有所帮助:

  • Toggle

    qc.Toggle组件用于开关或单选按钮,允许用户点击进行开关状态切换。

    Toggle开关由背景图、开启标记图、文本组成:



    作为一个可交互组件,同Button一样可以有3种状态(State):普通、按下、不可用

    var node = game.add.toggle(parent);
    node.background.texture = game.assets.find('__builtin_resource__');
    node.background.frame = 'button.png';
    node.background.imageType = qc.UIImage.IMAGE_TYPE_SLICED;
    node.checkMark.texture = G.game.assets.find('__builtin_resource__');
    node.checkMark.frame = 'ok.png';
    node.checkMark.imageType = qc.UIImage.IMAGE_TYPE_SLICED;
    node.checkMark.width = 50;
    node.checkMark.height = 50;
    node.text.text = 'Toggle';
    node.text.color = new qc.Color(0xffffff);
    node.text.fontSize = 24;
    // 设置开关为选中状态
    node.on = true;
  • ToggleGroup

    可将qc.ToggleGroup逻辑脚本挂载在任意对象上,可以维护多个Toggle,提供单选按钮的功能,通过一个例子来体验其用法:

    从主菜单(游戏对象/开关)或工具条上的开关按钮,新建2个Toggle组件



    在UIRoot节点挂载ToggleGroup脚本



    在Inspector上设置ToggleGroup属性



    Toggle - 当前选中的开关节点
    Allow Off - 是否允许没有Toggle被选中的情况
    Toggles - 当前所有的开关列表

文章来自绿盟(xDowns.com)转载请注明来路。



上一篇文章:念旧,美国现如今使用最高的苹果还是iPhone5/5s []