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: 
joetesta
Roku Guru

why is my roRegion invalid?

Hello -
Sorry if this is a dumb question, it's late and think I'm going nuts trying to understand why this won't work; I've got what seems to be a bitmap and 4 integers but it keeps telling me it's invalid....?

myRegion = CreateObject("roRegion", bitmap, sprite.Getx(), sprite.GetY(), bitmap.ifDraw2D.GetWidth(), bitmap.ifDraw2D.GetHeight())

printAA(myRegion)
printAA(bitmap)
print "here " sprite.Getx().ToStr(), sprite.GetY().ToStr(), bitmap.ifDraw2D.GetWidth().ToStr(), bitmap.ifDraw2D.GetHeight().ToStr()


And here's the output I'm getting:
invalid
roBitmap
here 1397 440 137 205


Wish I could understand what I'm doing wrong, thanks for any help,
Joe
aspiring
0 Kudos
7 REPLIES 7
RokuMarkn
Visitor

Re: why is my roRegion invalid?

Your bitmap is only 137 x 205 but you are trying to create a region that starts at 1297,440, way outside the bounds of the bitmap. A region must lie entirely within the bounds of its bitmap.

--Mark
0 Kudos
joetesta
Roku Guru

Re: why is my roRegion invalid?

Thanks Mark.
Now I'm struggling to understand the difference between the sprite and the region from 'sprite.GetRegion()'; specifically, my sprite has non-zero X and Y values but the region from sprite.GetRegion() does not have those.

sprite = spriteObj.sprite
print "here is the sprite x " + sprite.Getx().ToStr()
print "here is the sprite y " + sprite.GetY().ToStr()

oldRegion = sprite.GetRegion()

print "oldRegion data: " + chr(10) + oldRegion.ifRegion.GetX().ToStr() + chr(10) + oldRegion.ifRegion.GetY().ToStr() + chr(10) + oldRegion.ifRegion.GetWidth().ToStr() + chr(10) + oldRegion.ifRegion.GetHeight().ToStr() +chr(10)


And here is the output from that
here is the sprite x 157
here is the sprite y 440
oldRegion data:
0
0
137
205


Why does the roRegion not get the same X and Y values as the parent sprite? tyvmia
aspiring
0 Kudos
NewManLiving
Visitor

Re: why is my roRegion invalid?

Your question is still related to Joel's answer. A region is located inside of a bitmap and cannot extend beyond the bounds of its bitmap. So your regions x and y positions would reflect the positions you created the region at. If you offset your region then those coordinates will change inside of the bitmap. Now a sprites x and y are where you locate it on the screen. It has nothing to do with the regions x,y. Like taking a picture of a landscape. The picture is a region or portion of the landscape and the Sprite would be the picture frame that you can hang anywhere on the wall. The pictures x y is where you took the picture in relation to the landscape. The sprites x,y is the location you hung the picture on the wall
My Channels: 2D API Framework Presentation: https://owner.roku.com/add/2M9LCVC
Updated: 11-11-2015 - Completed Keyboard interface
The Joel Channel ( Final Beta )
0 Kudos
joetesta
Roku Guru

Re: why is my roRegion invalid?

"NewManLiving" wrote:
Your question is still related to Joel's answer. A region is located inside of a bitmap and cannot extend beyond the bounds of its bitmap. So your regions x and y positions would reflect the positions you created the region at. If you offset your region then those coordinates will change inside of the bitmap. Now a sprites x and y are where you locate it on the screen. It has nothing to do with the regions x,y. Like taking a picture of a landscape. The picture is a region or portion of the landscape and the Sprite would be the picture frame that you can hang anywhere on the wall. The pictures x y is where you took the picture in relation to the landscape. The sprites x,y is the location you hung the picture on the wall


Thank you for the explanation. Ultimately I just want to replace a sprite with a new image. Is there a way to do that?
aspiring
0 Kudos
NewManLiving
Visitor

Re: why is my roRegion invalid?

Yes the sprites SetRegion
My Channels: 2D API Framework Presentation: https://owner.roku.com/add/2M9LCVC
Updated: 11-11-2015 - Completed Keyboard interface
The Joel Channel ( Final Beta )
0 Kudos
joetesta
Roku Guru

Re: why is my roRegion invalid?

"NewManLiving" wrote:
Yes the sprites SetRegion

Thanks but now I'm going in circles; I was trying to use SetRegion when I could not create a valid region, which is what got me posting originally. Is there any way you could elaborate? How do I set the region if I can't get a valid region from the sprite's region?

Update: OK I think I actually have this part and the trouble is that my images are not actually caching the bitmaps; in my bitmap object I see
status : FAILED
bitmap : invalid

Well thanks for your help NML!
Update: I got it working, thanks again Mark and NewManLiving!
aspiring
0 Kudos
Komag
Roku Guru

Re: why is my roRegion invalid?

sprites, regions, bitmaps, are definitely confusing, and took me forever to get working, and I still am not totally all clear about them. :?
0 Kudos