Roku Developer Program

Developers and content creators—a complete solution for growing an audience directly.
cancel
Showing results for 
Search instead for 
Did you mean: 
Highlighted
krh5150
Level 7

Loading Animation Example

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

Thanks,
Kevin
0 Kudos
3 Replies
Roku Employee
Roku Employee

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
Level 7

Re: Loading Animation Example

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

--Mark
0 Kudos
Roku Employee
Roku Employee

Re: Loading Animation Example

Smiley Surprisedops:
0 Kudos