Drawing packed sprites
Monkey Forums/Monkey Programming/Drawing packed sprites
| ||
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 |
| ||
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. |
| ||
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 ) |
| ||
Oops. Beaten to it. |
| ||
Thanks... I'm having a little trouble quickly getting info out of the docs... used to having "search." :) |
| ||
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. |
| ||
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. |
| ||
@Raptisoft You're looking for SetScissors, which does exactly that - clips rendering to a set rectangle. |
| ||
Look at the top right of the module docs. Nice, haven't seen that. That's the handicap using large widescreen monitors.. |
| ||
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... |
| ||
If you open file:///C:/Monkey/docs/modules/index.html#/mojo.graphics/SetBlend in your browser, do you see it? |
| ||
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. |
| ||
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. |
| ||
AFAIK Monk on Windows doesn't have Search due to some Internet Explorer issues. |
| ||
Adding nothing to this at all really, but those sprites are brilliant :) |
| ||
I echo what raz says - top quality |
| ||
Oh thanks very much... those are from my iPhone game Hoggy. With luck, Monkey will help me export it to Flash. |
| ||
Just watched a gameplay video of it :) If you can get it going on Android I'll happily buy a copy |
| ||
Hey just downloaded you game, nice and cute. Phil |
| ||
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? |
| ||
"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! =) |