Roku:如何在新屏幕上打开LabelList?

时间:2017-08-14 20:09:17

标签: xml roku brightscript

BrightScript ,如何在新屏幕上打开以下LabelList(主屏幕/场景)?

<?xml version = "1.0" encoding = "utf-8" ?>

<!--********** Copyright 2016 Roku Corp.  All Rights Reserved. **********-->

<component name = "LabelListExample" extends = "Group" initialFocus = "exampleLabelList" >

  <script type = "text/brightscript" >

    <![CDATA[

    sub init()
      m.top.backgroundURI = "pkg:/images/rsgde_bg_hd.jpg"

      example = m.top.findNode("exampleLabelList")

      examplerect = example.boundingRect()
      centerx = (1280 - examplerect.width) / 2
      centery = (720 - examplerect.height) / 2
      example.translation = [ centerx, centery ]

      m.top.setFocus(true)
    end sub

    ]]>

  </script>

  <children >

    <LabelList id = "exampleLabelList" >

      <ContentNode role = "content" >
        <ContentNode title = "Renderable Nodes" />
        <ContentNode title = "Z-Order/Parent-Child" />
        <ContentNode title = "Animations" />
        <ContentNode title = "Events and Observers" />
        <ContentNode title = "On Demand Example" />
      </ContentNode>

    </LabelList>

  </children>

</component>

1 个答案:

答案 0 :(得分:3)

我认为您需要更好地理解SceneGraph API,以便了解如何执行此操作。 在您的main.brs文件中,使用screen = CreateObject("roSGScreen")创建Roku屏幕,从该屏幕创建一个使用scene = screen.CreateScene("Scene")的场景。 因此,需要将所有自定义组件添加到该场景的XML文件中。 在components文件夹中创建两个单独的文件LabelListExample.brs和LabelListExample.xml。 在您的LabelListExample.brs中添加此

sub init()
      m.top.backgroundURI = "pkg:/images/rsgde_bg_hd.jpg"

      example = m.top.findNode("exampleLabelList")

      examplerect = example.boundingRect()
      centerx = (1280 - examplerect.width) / 2
      centery = (720 - examplerect.height) / 2
      example.translation = [ centerx, centery ]

      m.top.setFocus(true) 
end sub

在LabelListExample.xml中添加:

    <?xml version="1.0" encoding="UTF-8"?>
    <component name = "LabelListExample" extends = "Group" initialFocus = "exampleLabelList" >
    <script type="text/brightscript" uri="pkg:/components/LabelListExample.brs" />
    <children >

        <LabelList id = "exampleLabelList" >

          <ContentNode role = "content" >
            <ContentNode title = "Renderable Nodes" />
            <ContentNode title = "Z-Order/Parent-Child" />
            <ContentNode title = "Animations" />
            <ContentNode title = "Events and Observers" />
            <ContentNode title = "On Demand Example" />
          </ContentNode>

        </LabelList>

      </children>
    </component>

现在,在您的Scene.xml文件中,您应该添加以下内容:

<Poster
     id="justPoster"
     translation="[0, 0]"
     width="1280"
     height="720" 
  />

<Group id="customComponentView" visible="false">
    <exampleLabelList
       id="customComponent"
    />
</Group>

<Group id="defaultView" visible= "true">
  <Label id="justLabel"
        color="0xFFFFFF"
        translation="[50, 300]"
        wrap="true"
        width="1200"
        horizAlign="center"
        text="Hide me if you can"
        opacity="0.5"
        font = "font:MediumBoldSystemFont"
  />      
</Group>

所以最大的问题是:如何从仅包含label的defaultView到具有此Label List的customComponentView?简单来说,你只需要隐藏一个并显示另一个。你需要做的是在Scene.brs文件中添加onKeyEvent()函数(如果从.xml执行所有操作,则在Scene脚本中)。同样在Scene init()中首先使用:

初始化视图和组件
m.defaultView = m.top.findNode(defaultView)
m.customComponentView = m.top.findNode(customComponentView)
m.labelList = m.top.findNode(customComponent)
m.label = m.top.findNode(justLabel)

在onKeyEvent()函数中,当按下遥控器上的“确定”按钮时,您可以控制哪个视图可见:

m.defaultView.visible = false
m.customComponentView = true

当customComponentView变为可见时,您还需要设置焦点:

m.labelList.setFocus(true)

希望你能继续这样做。另请查看Roku文档以了解有关onKeyEvent()函数的更多信息。