Roku Developer Program

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

SwapLayers Problem

Sometimes when I use swaplayers, it can cause unexpected things to happen, for example, make the video on the left of the screen disappear even though they are not on the same layer, or not swap back when I use, for example

if chooseStreams = 0

m.canvas.swapLayers(8, -7)

end if

if chooseStreams = 0
m.canvas.swapLayers(-7, 8)

end if

Where a button press can change the value of chooseStreams.
Has any one else had similar problems?
0 Kudos
Level 10

Re: SwapLayers Problem

Without knowing the content of your layers it's hard to say what's happening, but in order for video to be visible all layers on top of it have to be transparent and use the "Source" CompositionMode.
My Channels: - Twitter: @TheEndlessDev
Instant Watch Browser (NetflixIWB), Aquarium Screensaver (AQUARIUM), Clever Clocks Screensaver (CLEVERCLOCKS), iTunes Podcasts (ITPC), My Channels (MYCHANNELS)
0 Kudos
Level 10

Re: SwapLayers Problem

Rather than using swaplayers(1,2) to switch 1 and 2 between each other, running a multi-staged swap tends to work best in my experience.
swaplayers(1,-1) 'note negative z-orders might not work, simply used as an example - move layer 1 to layer -1
swaplayers(2,1) ' move layer 2 to layer 1
swaplayers(-1,2) 'move -1 layer to layer 2

This way you don't overwrite one of the layers - they are retained intact, and you don't have to redraw anything.
Swap the content Meta-Data stored in zOrderA with the content Meta-Data stored in zOrderB.
Enables the developer to change which layer is displayed “On Top”
It is possible to SwapLayers with empty (unspecified) layers.
Your performance may vary.
0 Kudos