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: 
btpoole
Channel Surfer

ClearLayer() Not Clearing

I have the following code which when remote button id=9 is pressed, a box (setlayer 10) is drawn on a section of the canvas and the first array element (setlayer 11) is displayed on part of the screen. As the remote button is pressed to scroll down id=3, the layers are to clear and then redraw changing the location of the box (setlayer 10) and advancing in the index of the array to display the next element. All this works with exception that the layers do not clear. When remote is pressed, initial box location and initial text location disappears very briefly and the new box is drawn in the correct location but the initial box is also still visible, same for the text, the new text is placed on top of the initial text. I can press the button for id=8 and all the desired layers clear as expected. I am using the same type of code in another section of the channel and it it works. Not sure why the layers are not clearing.


if id=9
m.yhilite=77 'start location of box
pTxt=265 'location of text
programindex=0
displaylist=[] 'text
descripbox=[] 'box
cid=m.guide[index]
xmlxfer=CreateObject("roUrlTransfer")
xmlport=CreateObject("roMessagePort")
xmlxfer.SetMessagePort(xmlport)
xmlxfer.SetUrl(cid) 'CALL XML URL
response=xmlxfer.GetToFile("tmp:/status.temp1") 'STORE TO FILE
readxml=ReadAsciiFile("tmp:/status.temp1") 'READ FILE
xml = CreateObject("roXMLElement")
IF xml.Parse(readxml) 'SETUP RETURN FOR PARSE

?"PARSED. . ."
descripbox.Push({ 'initial box
url: "pkg:/images/hilitebox.png"
TargetRect: {x: 350, y: m.yhilite, w: 300, h: 50}
})

displaylist.Push({ 'initial text
Text: xml.programme[programindex].desc.gettext()
TextAttrs: {color: "F9F5FA", VAlign: "middle", font: "small"}
TargetRect: {x:345, y:300, w: 300, h: 70}
})

m.canvas.setlayer(10, descripbox) 'set initial box layer
m.canvas.setlayer(11,displaylist) 'set initial text layer

while id <> 8 'LOOP UNTIL CANCEL IS CALLED
msg = wait(0, m.port)
if (msg.isRemoteKeyPressed())
id = msg.GetIndex()


if msg <> invalid 'IF PORT MESSAGE NOT INVALID

?"REMOTE BUTTON PRESSED. . ."id



if id=3 'SCROLL DOWN
?"REMOTE LOCATION. . ."programindex
m.canvas.clearlayer(10) 'clear the layer for box reposition
m.canvas.clearlayer(11) 'clear the layer for new text


m.yhilite= m.yhilite + 50 'move box down
programindex=programindex + 1 'MOVE FORWARD 1
programinfo={
desc: xml.programme[index].desc.gettext()
}

displaylist.Push({
Text: xml.programme[programindex].desc.gettext()
TextAttrs: {color: m.guidecolor, HAlign: m.channelalign, Direction: m.channeldirection, font: "small"}
TargetRect: {x:345, y:300, w: 300, h: 100}
})
descripbox.Push({
url: "pkg:/images/hilitebox.png"
TargetRect: {x: 350, y: m.yhilite, w: 300, h: 60}
})
m.canvas.setlayer(10, descripbox) 'set layer for new box location
m.canvas.setlayer(11,displaylist) 'set layer for new text
m.canvas.show() 'update screen

elseif id=8 'cancel out of loop
m.canvas.clearlayer(10)
m.canvas.clearlayer(11)
exit while

end if
end if
end if
end while
else
?"DIDNT PARSE"
endif





0 Kudos
5 REPLIES 5
cahillb
Visitor

Re: ClearLayer() Not Clearing

I can only say that I've had similar issues with ClearLayer not working. No idea why.

I use this hack:
canvas.SetLayer(layer_x, { color: "#00000000", CompositionMode: "Source" })
0 Kudos
btpoole
Channel Surfer

Re: ClearLayer() Not Clearing

Thanks for the suggestion. Do you use this in place of the clearlayer, then reset the layer to actual content?
Thanks
0 Kudos
RokuMarkn
Visitor

Re: ClearLayer() Not Clearing

I think the layer is clearing correctly, but your content arrays are accumulating all the different versions of your objects. I see you pushing the updated items onto descripbox and displaylist but never removing them.

--Mark
0 Kudos
btpoole
Channel Surfer

Re: ClearLayer() Not Clearing

Thanks Mark, I have tried something like discripbox=[] and displaylist=[] directly after m.canvas.show() thinking this would clear them out for the next but it still didn't work. This is not shown in the current code posted just because I had tried it and taken it out when I posted. Is there a more correct way of clearing the array I am not using?
Thanks

EDIT: Thanks again Mark, I used the above but moved it in the code and it works. Thanks
0 Kudos
EnTerr
Roku Guru

Re: ClearLayer() Not Clearing

"btpoole" wrote:
I have tried something like discripbox=[] and displaylist=[] directly after m.canvas.show() thinking this would clear them out for the next but it still didn't work. This is not shown in the current code posted just because I had tried it and taken it out when I posted. Is there a more correct way of clearing the array I am not using?

Yes - in your particular case would been better to do descriptBox.clear(): displayList.clear(). This way it would've worked even if placed after setLayer(), where re-assigning empty list to the variables have to be before setLayer() (since it remember the object/pointer, not the variable name).
0 Kudos