Error 1009, GrabImage, onRender and Eh?

Monkey Forums/Monkey Programming/Error 1009, GrabImage, onRender and Eh?

Dabz(Posted 2011) [#1]
While trying to compile Flash, I've come across a bit of a "thing"

I realize that only rendering commands can be used in onRender, this makes sense... But the thing that doesnt make sense is that since I've read somewhere on here that LoadImage(path$,fw,fh,fs,fc,flags) or whatever it is will be phased out, we should use:-

 Local atlas:=LoadImage("Image.PNG")
image = atlas.GrabImage(yadda,yadda,yadda)


Though, and this is where it gets me, how can this be a good idea in a sense where everything I have to load up has to be done in onRender, because as soon as I use GrabImage elsewhere, I receive a 1009?

My original code where I used GrabImage in, say, a type New method when creating an object in onCreate (Because that makes sense) worked in HTML5, but, as soon as I tried it on flash, it was "Oh no your not, blue screen for you laddie"

Confirmation on what the best course of action is, because loading stuff in onRender (Where only graphic commands can be used) seems a bit, well, odd!

Cheers

Dabz

EDIT: This is what I was referring too: http://www.monkeycoder.co.nz/Community/post.php?topic=149&post=1274


therevills(Posted 2011) [#2]
Hey Dabz,

You should be loading within the OnCreate method... could you supply a little example of the error?


Dabz(Posted 2011) [#3]
Hey up Mr T...

Error:-

TypeError: Error #1009
/Users/michaeldenathorn/Documents/test/test.monkey<39>
/Users/michaeldenathorn/Documents/test/test.monkey<18>
/Users/michaeldenathorn/Monkey/MonkeyPro36/modules/mojo/app.monkey<59>



Code:-


When I remove the two lines in the New Method and just run it as is, it compiles and runs fine, as in, this works in Flash as expected:-



Dabz


Sledge(Posted 2011) [#4]
Not fond of what you're attempting there -- is there any guarantee that New()'s local atlas will actually be persistent? Anyway I'd suggest you refactor it so as to have a bank of images/atlas' in MyGame (or some specified asset class) and let classes like CTest have fields that reference them.

I realize that only rendering commands can be used in onRender
Is that right? I thought it was more that rendering commands can only be used in OnRender(), which isn't quite the same thing.


skid(Posted 2011) [#5]
I think this is actually a bug with trans/flash.monkey which looks like it only recognizes lower case extensions, try changing the file name and source reference to "tiles.png", if this fixes it I think you should post a bug report.


therevills(Posted 2011) [#6]
Yeah, Simon is right. Have your actual filename extension in lower case... call load it in lowercase too ;)

It was fun to test this... I had HTML5 working and Flash failing, then altered one thing and I had HTML5 failing and Flash working...


Dabz(Posted 2011) [#7]

I think this is actually a bug with trans/flash.monkey which looks like it only recognizes lower case extensions, try changing the file name and source reference to "tiles.png", if this fixes it I think you should post a bug report.



Right, changed this and it worked... It was the only thing I didnt try, lol.. Typical! :D

Cheers fella's!


Not fond of what you're attempting there -- is there any guarantee that New()'s local atlas will actually be persistent?



It doesnt need to be persistant does it, it loads the tiles, I copy them, then hopefully 'atlas' will be destroyed, leaving me with a copied (None referenced) version.


Is that right? I thought it was more that rendering commands can only be used in OnRender(), which isn't quite the same thing.



Your right, my mistake, me bad... I just took it as it didnt work because it was outside of onRender! :)

Right, thanks for that fella's, much appreciated! :)

Dabz


Sledge(Posted 2011) [#8]
It doesnt need to be persistant does it, it loads the tiles, I copy them, then hopefully 'atlas' will be destroyed, leaving me with a copied (None referenced) version.

Unless things have changed, images grabbed from an atlas are just rects into the original - wouldn't be much point using an atlas otherwise.


Dabz(Posted 2011) [#9]

Unless things have changed, images grabbed from an atlas are just rects into the original - wouldn't be much point using an atlas otherwise.



I don't know if you clicked the link Sledgey at the top, the code was offered by Mark in that thread as a replacement for the soon to be removed overloaded LoadImage() method in respect of chopping a image up into cells.

The code is the exact same as the above mentioned method, but not wrapped, this is apparently being removed to stop images being loaded behind the scenes.

Dabz


Sledge(Posted 2011) [#10]
Hadn't seen it as I was having a quick browse on the ol' iPod during a break but yeah, what I mean is that GrabImage returns you a particular rect into a particular texture (which is what I guess an "image" must be to Monkey) rather than a new texture -- it doesn't copy anything*. I'd guess that being referenced in such a fashion makes the atlas texture GC-immune (so that's that worry covered) but by potentially re-loading the same atlas to grab different images you'd be reintroducing the problem that the deprecation was supposed to avoid! That's why I'm frowning and suggesting that you have a centralised asset store for new instances of in-game objects to GRAB their images from.



*This is my understanding based on being told that grabimage just gives you a rect into an atlas -- lambaste away if that's technically incorrect (I never did look at the mojo source).