"BrightScript/XML Markup Equivalence" wrote:
... you can also create and add nodes to the Scene Graph tree dynamically in BrightScript as needed for your application (for example, in response to user input). You can also configure existing or new nodes in the Scene Graph tree at any time in BrightScript. When and how you create and configure the Scene Graph node tree scene in your application XML files should depend on the intended flow of your Scene Graph application.
[...]
But a node can be created in BrightScript at any time, using functions like CreateObject() and createChild(); you don't have to use XML markup at all if your application is easier to write by creating Scene Graph nodes dynamically as needed.
node.onKeyEvent = function(key, isPressed): ? key, isPressed: end functionTo top it off, anonymous functions are actually p-code literals so even if i was doing such assignments in a loop all day long, that would neither cause repeat parsing nor new memory to be allocated - since that's a literal in B/S, just like "string literal" is. Beautiful.
<?xml version="1.0" encoding="utf-8" ?>
<component name="myComponent" extends="Group">
<script type="text/brightscript" uri="pkg:/components/myGroup.brs" />
</component>
"TheEndless" wrote:
As far as I'm aware, you still have to have an XML file that defines the component, otherwise SceneGraph won't be able to find the component you're trying to create. I don't think there's any way to register a component with SceneGraph via code.
... specific init() and onKeyEvent() functions. Note that those are not methods on the component itself, but rather intrinsic event handler functions.
"EnTerr" wrote:
You mean if i want to "extend" an existing component?! I don't want to do that... why would i?
"EnTerr" wrote:... specific init() and onKeyEvent() functions. Note that those are not methods on the component itself, but rather intrinsic event handler functions.tOmato, tomAto - it's a question of what you name them. Event handlers which are functions that get invoked by magic-name... call them methods or not, it would be best they get accessible name slots in the node, so they can be assigned to or called directly... no?
<?xml version="1.0" encoding="utf-8" ?>
<component name="myScene" extends="Scene">
<script type="text/brightscript" uri="pkg:/components/myScene.brs" />
</component>
"TheEndless" wrote:"EnTerr" wrote:
You mean if i want to "extend" an existing component?! I don't want to do that... why would i?
I'd expect at the very least you'd want to extend a Scene node, but if not, you still need a way to hook into it's context, and there's no way to do that without extending it. Additionally, if you want to take advantage of the multi-threading capabilities of SceneGraph, then you'll have to extend the Task node. It can't be used generically, because the "functionName" has to be the name of a function that is defined inside the Task's context, which again, can only be established by specifying the <script/> that belongs to that Task.
node.setFunction(name as string, fn as function)
node.getFunction(name as string) as function ' optional
node.getFunctions() ' optional, return AA of all functions assoc with a node
node.addField("myFunc", "function", false)
node.myFunc = function() ...
"EnTerr" wrote:
I think you are having a cognitive bias, in which doing some SG XML programming for a while, it feels to you subclassing is the only - and natural way to do things. It ain't.
"EnTerr" wrote:
Now, if i had this feature (it may already exist for all i know - but if not, it's rather simpler to add) - can you think of a reason i would need to "extend" anything into anything?
"The Docs Guy " wrote:
It would probably be good for me to revise and clarify the section of documentation that got the guy all “hot and bothered”, since it already needs some clarification anyway.
By “BrightScript”, I meant “BrightScript within an XML component file <script> element CDATA section”, not the “main BrightScript thread”.
You can’t do much with the “main BrightScript thread” except kick off the Scene Graph render thread, that starts in an EXTENDED “Scene” component XML file.
Wishful thinking, thinking based on previous Roku programming models, whatever, it’s the first trap programmers fall into with Scene Graph. One of the first things I wrote about Scene Graph is some totally nonsensical paragraph about being able to create and add any number of “Scenes” in BrightScript using createObject(). (It may still be in there, another thing to fix.)
"Lead Roku Scenegraph Engineer" wrote:
You can actually create nodes in the main Brightscript thread. The problem is that it’s generally much slower to do things that way because of all the synchronization that has to be done with the scene graph render thread.
It’s much faster to create nodes in the scripts inside an XML component that extends “Scene” (or in other XML components), since those scripts run in the render thread and avoid synchronization penalties.
"RokuJoel" wrote:
Hmm - what about the thing I posted yesterday- perhaps I need to reread your questions, but I think that might be a similar thing to what you are asking - how to create and add nodes to a scenegraph node from the main brightscript thread?
We’re upgrading Roku Community to bring you a faster, more mobile-friendly experience. You may notice limited functionality or read-only access during this time. Read more here.
Planned Downtime:
Community will be unavailable for up to 24–48 hours during the upgrade window during the week of May 19th and you may notice reduced functionality.
In the meantime, for additional assistance, visit our Support Site.
We're sorry for this disruption — we’re excited to share what’s next!