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

Can't move text drawn on an roImageCanvas

I'm having some problems animating some text using an roImageCanvas.

Here's my initialization code, copied straight from the Component Reference Guide:
    m.canvasItems = {
Text: GetInfoBlock()
TextAttrs: {
Color: "#FFCCCCCC"
Font: "Medium"
HAlign: "HCenter"
VAlign: "VCenter"
Direction: "LeftToRight"
}
TargetRect: {
x: m.display_size.w/4
y: m.display_size.h/4
w: m.display_size.w/2
h: m.display_size.h/2
}
}

m.canvas = CreateObject("roImageCanvas")
port = CreateObject("roMessagePort")
m.canvas.SetMessagePort(port)
'Set opaque background
m.canvas.SetLayer(0, {Color:"#FF000000", CompositionMode:"Source"})
m.canvas.SetLayer(1, m.canvasItems)
m.canvas.Show()


From time to time, I run this:
        m.canvasItems.Text = GetInfoBlock()
m.canvas.SetLayer(1, m.canvasItems)
and the screen updates as expected. However, I'm also trying to bounce the text around the screen, and that isn't working.

Here's the place where I'm animating:
Sub sleep_ten_minutes()
m.timespan.Mark()
While true
sleep(20)
If m.timespan.TotalSeconds() >= 600 Then Return
animate(m.canvasItems.TargetRect, m.animation)
print m.canvasItems.TargetRect.x;",";m.canvasItems.TargetRect.y
m.canvas.SetLayer(1, m.canvasItems)
End While
End Sub

When I run it, I see this on my PuTTY session:
... inner loop...
321 , 181
322 , 182
323 , 183
[...]
499 , 359
500 , 360
501 , 359
but the text on the screen never moves. Can anyone help? Thanks!
0 Kudos
6 REPLIES 6
TheEndless
Channel Surfer

Re: Can't move text drawn on an roImageCanvas

Are you calling AllowUpdates() anywhere on the canvas itself? Perhaps it was set to false inadvertently someplace, and never reset back to true...?
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
RokuJoel
Binge Watcher

Re: Can't move text drawn on an roImageCanvas

Well, we don't know what is happening in the animate function. The items in SetLayer should be in an array though:

m.canvas.setlayer(1,[m.canvas.items])

or you could do

        m.canvasItems =[{
Text: GetInfoBlock()
TextAttrs: {
Color: "#FFCCCCCC"
Font: "Medium"
HAlign: "HCenter"
VAlign: "VCenter"
Direction: "LeftToRight"
}
TargetRect: {
x: m.display_size.w/4
y: m.display_size.h/4
w: m.display_size.w/2
h: m.display_size.h/2
}
}]
0 Kudos
samwyse
Channel Surfer

Re: Can't move text drawn on an roImageCanvas

"TheEndless" wrote:
Are you calling AllowUpdates() anywhere on the canvas itself? Perhaps it was set to false inadvertently someplace, and never reset back to true...?

As I expected, grep doesn't find AllowUpdates anywhere in my code. And as I said, the text is updating just fine. 😞 I'm going to try shoving a new copy of TargetRect in, maybe it needs to change instead of just its contents.

"RokuJoel" wrote:
Well, we don't know what is happening in the animate function. The items in SetLayer should be in an array though

The animate function just updates the TargetRect. At first I thought maybe it was updating a copy, which is why I put the print where I did, to verify that the numbers were changing. And the Component Ref says that there are two ways to call it: Void SetLayer(int zOrder, roAssociativeArray contentMetaData) or Void SetLayer(int zOrder, roArray contentList). But I'm desperate enough to try anything at this point.
0 Kudos
RokuJoel
Binge Watcher

Re: Can't move text drawn on an roImageCanvas

Void SetLayer(int zOrder, roAssociativeArray contentMetaData) or Void SetLayer(int zOrder, roArray contentList).


both work, but generally it seems to work better if you use the second.

Also, all targetrect values must be integers.

- Joel
0 Kudos
RokuChris
Roku Employee
Roku Employee

Re: Can't move text drawn on an roImageCanvas

Have you tried calling Show() to force the canvas to update?
0 Kudos
samwyse
Channel Surfer

Re: Can't move text drawn on an roImageCanvas

"RokuJoel" wrote:

Also, all targetrect values must be integers.

- Joel

JACKPOT!!!

I was setting my initial target rect to fractions of my display size, which meant I was using floats instead of ints. And after fixing that, it turns out that my animate routine is using multiplications, which also seem to result in floats. Adding calls to Int() everywhere I do an assignment to any of the target rect values has fixed everything.

Thanks!
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.