samwyse
Channel Surfer
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-07-2012
01:41 PM
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:
From time to time, I run this:
Here's the place where I'm animating:
When I run it, I see this on my PuTTY session:
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()and the screen updates as expected. However, I'm also trying to bounce the text around the screen, and that isn't working.
m.canvas.SetLayer(1, m.canvasItems)
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...but the text on the screen never moves. Can anyone help? Thanks!
321 , 181
322 , 182
323 , 183
[...]
499 , 359
500 , 360
501 , 359
6 REPLIES 6

TheEndless
Channel Surfer
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-07-2012
01:55 PM
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)
Instant Watch Browser (NetflixIWB), Aquarium Screensaver (AQUARIUM), Clever Clocks Screensaver (CLEVERCLOCKS), iTunes Podcasts (ITPC), My Channels (MYCHANNELS)

RokuJoel
Binge Watcher
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-07-2012
02:01 PM
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.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
}
}]
samwyse
Channel Surfer
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-07-2012
02:36 PM
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.

RokuJoel
Binge Watcher
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-07-2012
02:41 PM
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


Roku Employee
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-07-2012
03:16 PM
Re: Can't move text drawn on an roImageCanvas
Have you tried calling Show() to force the canvas to update?
samwyse
Channel Surfer
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-07-2012
03:22 PM
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!