Roku Developer Program

Join our online forum to talk to Roku developers and fellow channel creators. Ask questions, share tips with the community, and find helpful resources.
cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 
_rossbower
Visitor

Create animation in BrightScript?

I would like to create an animation node purely in BrightScript, no XML involved. I have created the following function:


function SymetricScaleAnimation(target as object) as object
print "In SymetricScaleAnimation"
animation = CreateObject("roSGNode", "Animation")
animation.duration = .15
animation.repeat = true
animation.easeFunction="linear"
animatin.id = "animateScaleBS"

interp = CreateObject("roSGNode", "Vector2DFieldInterpolator")
interp.key = [0.0, 1.0]
interp.keyValue = [[1,1], [3,3]]
interp.fieldToInterp = target.id + ".scale"
animation.AppendChild(interp)

return animation
end function


This mirrors an animation node I have created in XML. As far as I can tell, all fields are identical on my programmatically-created animation node and my XML-created node. However, the animation node I created in code doesn't run, while the one I created in XML does. Is created animation nodes in BrightScript not supported? If so, why not? What prevents this from working?
0 Kudos
3 REPLIES 3
TheEndless
Channel Surfer

Re: Create animation in BrightScript?

You have a typo in the code.
animatin.id = "animateScaleBS"

I wonder if that's causing it to crash the thread or if it's a copy/paste error in your post. Are you seeing any errors in the SG debugger consoles?
My Channels: http://roku.permanence.com - Twitter: @TheEndlessDev
Instant Watch Browser (NetflixIWB), Aquarium Screensaver (AQUARIUM), Clever Clocks Screensaver (CLEVERCLOCKS), iTunes Podcasts (ITPC), My Channels (MYCHANNELS)
0 Kudos
RokuJoel
Binge Watcher

Re: Create animation in BrightScript?

Engineering says:

Animaton nodes have to be associated with a Scene in order to work. If they are created in the scene graph render thread, that happens by default. If you create them in the main Brightscript thread or a task thread, it doesn’t.

In that case, parenting the Animation node to any node in the Scene’s scene graph will cause that association to happen. So instead of using CreateObject(“roSGNode”, “Animation”), try this:

animation = someNode.createChild(“Animation”)

where someNode is either the Scene node or any node that is parented to the Scene.

Generally, other than ContentNodes, creating nodes in the main Brightscript thread is not a recommended best practice for using the scene graph APIs.



Joel
0 Kudos
_rossbower
Visitor

Re: Create animation in BrightScript?

"RokuJoel" wrote:
Engineering says:

Animaton nodes have to be associated with a Scene in order to work. If they are created in the scene graph render thread, that happens by default. If you create them in the main Brightscript thread or a task thread, it doesn’t.

In that case, parenting the Animation node to any node in the Scene’s scene graph will cause that association to happen. So instead of using CreateObject(“roSGNode”, “Animation”), try this:

animation = someNode.createChild(“Animation”)

where someNode is either the Scene node or any node that is parented to the Scene.

Generally, other than ContentNodes, creating nodes in the main Brightscript thread is not a recommended best practice for using the scene graph APIs.



Joel


Thanks Joel, this solved my issue! I ended up creating a component and defining the animations in XML, but reparenting the animations was the key.
0 Kudos