#Setting up a SceneGraph application
##Task objective: Set up a SceneGraph application with correct directory structure and get it running on the box.
The way SceneGraph applications are set up with regards to directory structure are different than previous SDK1 applications.
Have a read of the information here: https://sdkdocs.roku.com/display/sdkdoc/Developing+Scene+Graph+Applications
Basically you have your directory structure like this:
- components
- images
MakeFile
manifest
- source
To run your application you will need a Main function that creates a screen in a Main.brs file. Your Main.brs file should be in your source
folder. Here is an example of a Main.brs file:
sub Main()
showChannelSGScreen()
end sub
sub showChannelSGScreen()
print "in showChannelSGScreen"
screen = CreateObject("roSGScreen")
m.port = CreateObject("roMessagePort")
screen.setMessagePort(m.port)
scene = screen.CreateScene("mainScene")
screen.show()
while(true)
msg = wait(0, m.port)
msgType = type(msg)
if msgType = "roSGScreenEvent" then
if msg.isScreenClosed() then
return
end if
end if
end while
end sub
As you can see above we created a scene called mainScene
. This needs to be implemented. In SceneGraph applications there are two different file types we use. *.brs and *.xml - we generally use the xml files for views and the *.brs files for everything else. You can embed BrightScript code into the xml files but I’ve often found it good practice to separate the two.
So if you create a file called components/mainScene/MainScene.xml
and write the following code in it.
<?xml version="1.0" encoding="utf-8" ?>
<component name="MainScene" extends="OverhangPanelSetScene" >
<interface>
</interface>
<children>
</children>
<script type="text/brightscript" uri="pkg://components/mainScene/MainScene.brs" />
</component>
Notice that we have included a brs file within it (<script type="text/brightscript" uri="pkg://components/mainScene/MainScene.brs" />
). This brs file would usually contain the business logic for the view - like a mediator/controller. In this example though it’s cool just to print something out - like this (create this in components/mainScene/MainScene.brs):
function init() as Void
? "howdy"
end function
Note how the init()
method is always called on object creation - like a constructor.
##Getting the app on the box
Now getting the application on to the box. To make things easier I have a MakeFile that I use (http://wegoo.d.pr/Fysh). To run this makefile download it to the root directory of your application. Open a shell in your root and execute (where 192.168.1.XXX is the IP of your box):
export ROKU_DEV_TARGET=192.168.1.XXX
Once you have done this you can simply type:
make install
to install your app.
Have a play around and get your app on the box - add a few components to the view if you like. Also have a look at the manifest file and add some different splash screens there etc.
To view trace output/errors you can telnet into your box.
telnet 192.168.1.XXX 8085
On firmware less than 7.5 you can use ports 8085 - 8089 for different outputs (main app, threads, component traces) but on firmware 7.5 all of this is amalgamated on port 8085 (which is loads easier).
@Andrii87 I believe this was the next part - although it's been a while since I checked! https://gist.github.com/rymawby/7622aa9a0c1548df5eff530728d5859f Hope this helps.