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

Remove layer from top or middle using RoScreen

It has become apparent that I will need to use roScreen in my program instead of roImageCanvas
in order to speed up my program, regarding layer in roImageCanvas, use the setLayer, clearLayer and swapLayer
but when i am using roScreen how i will remove layer that is in top or middle without remove the first layer.

I am giving code in that i want to remove middle layer that i.e "pkg:/images/2.jpg

sub main()
screen=createobject("roscreen",true)
'screen.setalphaenable(false)
screen.setalphaenable(true)
image1=createobject("robitmap","pkg:/images/1.jpg")
image2=createobject("robitmap","pkg:/images/2.jpg")
image3=createobject("robitmap","pkg:/images/3.jpg")
'lets set up some positions for these images:
obj1={posx:100,posy:100}
obj2={posx:200,posy:200}
obj3={posx:300,posy:300}
timer=createobject("rotimespan")
timer.mark()

while true
screen.setalphaenable(true)
screen.clear(&h000000ff)
screen.drawobject(obj1.posx,obj1.posy,image1)
screen.setalphaenable(false)
screen.drawobject(obj2.posx,obj2.posy,image2)

screen.setalphaenable(false)
screen.drawobject(obj3.posx,obj3.posy,image3)
screen.swapbuffers()
end while
end sub



Any suggestions?
0 Kudos
5 REPLIES 5
RokuMarkn
Visitor

Re: Remove layer from top or middle using RoScreen

You would just add an "if" statement to decide whether to draw the bitmap.

screen.clear(&h000000ff)
screen.drawobject(obj1.posx,obj1.posy,image1)
if should_draw_layer_2 then
screen.setalphaenable(false)
screen.drawobject(obj2.posx,obj2.posy,image2)
end if
screen.setalphaenable(false)
screen.drawobject(obj3.posx,obj3.posy,image3)


--Mark
0 Kudos
umesh1988
Visitor

Re: Remove layer from top or middle using RoScreen

Thanks, But I am already drawing three images using Bitmap in three layer In the given code, my requirement is that how to remove or hide the layer that is in top or middle without hide the first Image.
0 Kudos
TheEndless
Channel Surfer

Re: Remove layer from top or middle using RoScreen

"umesh1988" wrote:
Thanks, But I am already drawing three images using Bitmap in three layer In the given code, my requirement is that how to remove or hide the layer that is in top or middle without hide the first Image.

RokuJoel gave you the code to do that. In your While loop, you need to add logic that only draws the layers you want displayed.
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
umesh1988
Visitor

Re: Remove layer from top or middle using RoScreen

We are using roScreen to display a static map and on top of static map we are animating a group of 10 images for overlay.

Following is the code for animating the overlay image. Where m.mylocal[] contains path of 10 local images

Function Animate()
while true
m.screen.SetAlphaEnable(true)
for j=0 to 9 step 1
sleep(500)
bitmap=CreateObject("roBitmap", m.mylocal[j])
m.screen.DrawObject(0,0, bitmap)
m.screen.Finish()
end for
end while
end function


The problem is we are not able to remove the animating overlay images from the stack. so after some time the black screen is appearing on the screen.

Please advise how we can clear the stack of overlay without hiding static map.
0 Kudos
RokuJoel
Binge Watcher

Re: Remove layer from top or middle using RoScreen

First of all, you are doing something very inefficient which is creating the bitmaps at the same time you are drawing them. If they need to be animated, create an animated sprite from an array of regions, or create an array of bitmaps and draw those in your loop:

As to hiding images, you would want to have a conditional value in an array parallel to the bitmap array as to whether something should display or not. Here's an example:




Function SetupAnimation()
m.screen.SetAlphaEnable(true)
m.animationArray=createobject("roArray",9,true)
m.drawarray=createobject("roArray",9,true)

for j=0 to 9 step 1
m.animationArray[j]=CreateObject("roBitmap", m.mylocal[j])
m.drawarray[j]=true
end for
end function

Function Animate()
animation_timer=createobject("rotimespan")
animation_timer.mark()
m.screen.SetAlphaEnable(true)
j=0
while true
if animation_timer.totalmilliseconds() >= 500 then
if m.drawarray[j] then
m.screen.DrawObject(0,0, bitmap)
end if
animation_timer.mark()
end if
j=j+1
if j > 9 then j=0

end while
end function



This way you can do other things and your UI won't have to pause for 500ms for animation updates.

- Joel
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.