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

DefenderBitmapSet and Regions

Hello,

I hope I can phrase this question properly. First, some XML for reference:

In "pkg:/assets/sprite.map.xml":

<DefenderBitmapSet>

<Bitmap name="gameTiles" filespec="pkg:/assets/tiles.png">
<Region name="selectedTile" x="00" y="00" w="32" h="32"/>
<Region name="defaultTile" x="32" y="00" w="32" h="32"/>
</Bitmap>

</DefenderBitmapSet>


And the main brs code:

Library "v30/bslDefender.brs"

Function Main ()

app = { }
app.tiles = GetGameTiles()

Print app.tiles.bitmapset.regions

End Function

Function GetGameTiles () As Object

tiles = { }
tiles.bitmapset = dfNewBitmapSet(ReadAsciiFile("pkg:/assets/sprite.map.xml"))

Return tiles

End Function


Running the code, everything seems fine so far:

Output:

------ Running ------
dfNewBitmapSet: no <Background> tag in BitmapSet
gameTiles: <Component: roRegion>
gameTiles.defaultTile: <Component: roRegion>
gameTiles.selectedTile: <Component: roRegion>




But when I try to access the region with...



Print app.tiles.bitmapset.regions.gameTiles.defaultTile



I get an error thrown...


Output:

Current Function:
003: Function Main ()
004:
005: app = { }
006: app.tiles = GetGameTiles()
007:
008: Print app.tiles.bitmapset.regions.gameTiles.defaultTile
009:
010: End Function
Syntax Error. (runtime error &h02) in ...rpANq/pkg:/source/appMain.brs(8)

008: Print app.tiles.bitmapset.regions.gameTiles.defaultTile
Backtrace:
Function main() As
file/line: /tmp/plugin/BBBA...rpANq/pkg:/source/appMain.brs(8)

Local Variables:
global &h0020 rotINTERFACE:ifGlobal
m &h0010 bsc:roAssociativeArray, refcnt=2
app &h0010 bsc:roAssociativeArray, refcnt=1



Shouldn't I be getting an roRegion traced? I've use the XML file with animation tags successfully before, so I assumed I could just use a single bitmap and use the regions with the NewSprite command instead of NewAnimatedSprite. Is that not possible? Do I need to have a separate bitmap tag for each?

I'm putting together a development tutorial, so any help appreciated. Thanks in advance.

-dev
0 Kudos
4 REPLIES 4
RokuJoel
Binge Watcher

Re: DefenderBitmapSet and Regions

My first guess is that your regions might be out of bounds of the actual size of the image you are working with and thus is returning Invalid. Otherwise, can you print out all the parts of app.tiles, like:

Print app.tiles

?app.tiles.bitmapset

?app.tiles.bitmapset.regions.gameTiles

That will give you an idea of what the value is that is triggering the error.
0 Kudos
TheEndless
Channel Surfer

Re: DefenderBitmapSet and Regions

I believe the format for accessing sub-regions is:
app.tiles.bitmapset.regions["gameTiles.defaultTile"]

instead of
app.tiles.bitmapset.regions.gameTiles.defaultTile
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
develephant
Visitor

Re: DefenderBitmapSet and Regions

"TheEndless" wrote:
I believe the format for accessing sub-regions is:
app.tiles.bitmapset.regions["gameTiles.defaultTile"]

instead of
app.tiles.bitmapset.regions.gameTiles.defaultTile


Excellent. I saw that method in the docs, but was only applying it to the last value, which wasn't working. While I think this style of accessing the properties is a bit obscure, it does indeed work.

I had rewritten most of my piece to just use a single frame animation tag, which works great but seems like overkill.

Many thanks for your response. 😉

-dev
0 Kudos
bandal
Visitor

Re: DefenderBitmapSet and Regions

What will you cover in your tutorial? I am curious. How soon till it comes available?
0 Kudos