Drawing packed sprites

Monkey Forums/Monkey Programming/Drawing packed sprites

Raptisoft(Posted 2011) [#1]
For speed reasons on iPhone and Android, I group all my images together on one texture using a texture packing tool.

Like this:


My packer tool can output the coordinates of each sprite on that texture... how can I get to them in Monkey? I can load the image as a sprite... but how do I draw only from a certain rect on it?

Thanks,
John


Indiepath(Posted 2011) [#2]
DrawImageRect( image:Image, x#, y#, srcX, srcY, srcWidth, srcHeight, rotation#, scaleX#, scaleY#, frame=0 )

image - image to draw.
x, y - coordinates to draw image at.
srcRect - source rectangle.
srcX, srcY, srcWidth, srcHeight - source rectangle.
rotation - local image rotation in degrees.
scaleX, scaleY - local image scale.


Beaker(Posted 2011) [#3]
From the docs:
Function DrawImageRect( image:Image, x#, y#, srcX, srcY, srcWidth, srcHeight, frame=0 )

Function DrawImageRect( image:Image, x#, y#, srcX, srcY, srcWidth, srcHeight, rotation#, scaleX#, scaleY#, frame=0 )


Beaker(Posted 2011) [#4]
Oops. Beaten to it.


Raptisoft(Posted 2011) [#5]
Thanks... I'm having a little trouble quickly getting info out of the docs... used to having "search." :)


Raptisoft(Posted 2011) [#6]
At risk of cluttering the forums, I'll ask this here:

Is there a way, other than esoteric computation of scale, to draw my image within a quad?

For instance, is there any kind of DrawImageRect that will draw not with x#,y#, but x#,y#,width#,height#?

I use this technique in a lot of my special effects, but most important is one of the ways I handle multiresolution. For instance, the iPhone version will run at 480x320, while the Windows one will run at 1024x768. The iPhone one will have a MUCH smaller texture resource, but the same coordinate system in-game... so if I simply let Monkey scale things down for me, the smaller texture will mean everything renders very tiny, because I shrunk the texture so much. But if I can specify a quad to draw the Sprite on, then I can resize that texture with abandon, and it'll always be the same size in-game.


Perturbatio(Posted 2011) [#7]
Thanks... I'm having a little trouble quickly getting info out of the docs... used to having "search." :)


Look at the top right of the module docs.


sknightly(Posted 2011) [#8]
@Raptisoft You're looking for SetScissors, which does exactly that - clips rendering to a set rectangle.


Volker(Posted 2011) [#9]
Look at the top right of the module docs.

Nice, haven't seen that. That's the handicap using large widescreen monitors..


Raptisoft(Posted 2011) [#10]
Perturbatio:
I still don't see it... I'm also on widescreen. Top right of "Docs?" It just has Monkey, centered. Above it, it looks like something might be cut off in the Windows UI...


Perturbatio(Posted 2011) [#11]
If you open file:///C:/Monkey/docs/modules/index.html#/mojo.graphics/SetBlend in your browser, do you see it?


Raptisoft(Posted 2011) [#12]
Oh, now I do. Thank you much... I was viewing that through the Monkey IDE itself, and it wasn't wide enough on my screen to show up.


Perturbatio(Posted 2011) [#13]
It's not the width, it's because the Monk IDE is using:
file:///C:/Monkey/docs/modules/index_winmonk.html#/mojo.graphics/SetBlend

instead of:
file:///C:/Monkey/docs/modules/index.html#/mojo.graphics/SetBlend

I only found it because JungleIDE uses the second URL, the search is commented out on the first one.


matt(Posted 2011) [#14]
AFAIK Monk on Windows doesn't have Search due to some Internet Explorer issues.


Raz(Posted 2011) [#15]
Adding nothing to this at all really, but those sprites are brilliant :)


matt(Posted 2011) [#16]
I echo what raz says - top quality


Raptisoft(Posted 2011) [#17]
Oh thanks very much... those are from my iPhone game Hoggy. With luck, Monkey will help me export it to Flash.


Raz(Posted 2011) [#18]
Just watched a gameplay video of it :) If you can get it going on Android I'll happily buy a copy


filharvey(Posted 2011) [#19]
Hey just downloaded you game, nice and cute.

Phil


Wagenheimer(Posted 2011) [#20]
Raptisoft! Congratulations for the nice game! =)

"The iPhone one will have a MUCH smaller texture resource, but the same coordinate system in-game... "

Please, could you please explain a bit more this? Do you use the same texture for the Windows and Iphone version? How exactly do you do to keep the same coordinate system in-game using different game resolutions?


Wagenheimer(Posted 2011) [#21]
"For instance, is there any kind of DrawImageRect that will draw not with x#,y#, but x#,y#,width#,height#?"

Function DrawImageRect( image:Image, x#, y#, srcX, srcY, srcWidth, srcHeight, rotation#, scaleX#, scaleY#, frame=0 )

Well, do you have scaleX and scaleY available here, I think you can simulate your need of width#,height# using scales and some math! =)