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: 
krh5150
Visitor

Loading Animation Example

Does anyone have an example of a loading animation for a roImageCanvas?

Thanks,
Kevin
0 Kudos
3 REPLIES 3
RokuJoel
Binge Watcher

Re: Loading Animation Example

Here's something quick off the top of my head, since I have done it before:

find an animated "loading" gif online, and break it into separate image files, put them in a folder under your images folder like images/gfx

Create a set of objects, one for each image. Here, off the top of my head is about how I would do it:


function setupAnimation() as object
m.animation=[{url:"pkg:/images/gfx/frame0.png",compositionMode:"Source_Over",targetrect:{x:640,y:360,w:32,h:32}}
{url:"pkg:/images/gfx/frame1.png",compositionMode:"Source_Over",targetrect:{x:640,y:360,w:32,h:32}}
{url:"pkg:/images/gfx/frame2.png",compositionMode:"Source_Over",targetrect;{x:640,y:360,w:32,h:32}}
{url:"pkg:/images/gfx/frame3.png",compositionMode:"Source_Over",targetrect;{x:640,y:360,w:32,h:32}}
{url:"pkg:/images/gfx/frame4.png",compositionMode:"Source_Over",targetrect;{x:640,y:360,w:32,h:32}}
{url:"pkg:/images/gfx/frame5.png",compositionMode:"Source_Over",targetrect;{x:640,y:360,w:32,h:32}}]

m.animpointer=0
end function


function updateAnimation(screen as object, animation as object)
screen.setlayer(3,[animation[m.animpointer]])
m.animpointer=m.animpointer+1
end function


within whatever function is downloading and parsing data, you want to periodically call updateAnimation. You'll have to pass the screen and animation object around, or you could make them both globals, remove the parameters from the function call and then you could just call updateAnimation() from anywhere to draw the next frame.

- Joel
0 Kudos
RokuMarkn
Visitor

Re: Loading Animation Example

You probably also want to wrap m.animpointer back to zero when it reaches animation.count().

--Mark
0 Kudos
RokuJoel
Binge Watcher

Re: Loading Animation Example

:oops:
0 Kudos
Need Assistance?
Welcome to the Roku Community! Feel free to search our Community for answers or post your question to get help.

Become a Roku Streaming Expert!

Share your expertise, help fellow streamers, and unlock exclusive rewards as part of the Roku Community. Learn more.