DrawImageRect and MidHandle

Monkey Forums/Monkey Programming/DrawImageRect and MidHandle

Xaron(Posted 2013) [#1]
Hi guys,

as I'd like to use a texture packer I'll have to use DrawImageRect of course instead of DrawImage, BUT in that case I can't use the image flag MidHandle which is quite handy when you want to rotate images around its center.

Any ideas? I can't imagine I'm the first one with that "problem"?

Cheers!


Paul - Taiphoz(Posted 2013) [#2]
you don't use diddy do you ?

PowerUPImage[0]			=	ImageSpriteSheet.GrabImage(918,216,54,54,1,Image.MidHandle)'bomb



Paul - Taiphoz(Posted 2013) [#3]
Oh and obv that would mean you wont be using DrawImageRect you will just DrawImage normally.


Xaron(Posted 2013) [#4]
Oh well, thanks for pointing me to that one!


Paul - Taiphoz(Posted 2013) [#5]
Did that help ?


Xaron(Posted 2013) [#6]
I haven't tried yet. ;) But I think it will!


Supertino(Posted 2013) [#7]
I use a texture pack and can set a midhandle, though I wrote the texture packer code that extracts the images, I am sure I just grabimage(you can set handle here).


Xaron(Posted 2013) [#8]
Yes, GrabImage is the key! Thanks so much! GrabImage does not create a copy, does it?


Paul - Taiphoz(Posted 2013) [#9]
Do you mean a copy of the whole sprite sheet, or a copy of the small section that you grab ?

I think it grabs a small section and makes a fresh copy of that small part but I have not looked into it, didn't feel the need, it worked and did what I wanted of it ..


Xaron(Posted 2013) [#10]
Well if it creates a copy this doesn't make sense at all to pack the textures into one file.


Paul - Taiphoz(Posted 2013) [#11]
Yeah I see your point, then its still taking up extra space in memory, it must reference it then surely ?

food for thought.


Supertino(Posted 2013) [#12]
AFAIK grabimage just references the parent image and does not make a copy of the grab portion. I remember posting a thread a while back about some grab image weird-ness and we can to the conclusion it references.


Paul - Taiphoz(Posted 2013) [#13]
taking a quick look at the docs...

"GrabImage creates a new image by 'grabbing' a rectangular region of the current image."

that would suggest that it does create a little copy of that portion of the over all sprite sheet.

Mark ?


Supertino(Posted 2013) [#14]
As far as we could work out it does reference http://www.monkeycoder.co.nz/Community/posts.php?topic=2301#22522 changes made to the referenced image effect the grabbed images.


John McCubbin(Posted 2013) [#15]
Aye it references the image, so it's using the one surface, if you delete or change the image you 'grabbed' from the images you grabbed are changed/deleted. So just grab them, center and away you go :P


BigAnd(Posted 2013) [#16]
I use DrawImageRect and you can set the handle the same as you would a normal DrawImage.

Even if your sprite sheet is 2048x2048 and you want to draw a 16x16 sprite off your sprite sheet, you just set the handle on your sprite sheet to 8,8 and then draw your sprite with DrawImageRect.

The texture packer has to give you the width and height of the each sprite so you should just be able to do something like:

IMGspritesheet.SetHandle(sprite1_w/2,sprite1_h/2)
DrawImageRect(IMGspritesheet, sprite_x, sprite_y, spritesheet_x, spritesheet_y, sprite1_w, sprite1_h)