Game Development Community

Newbie question about t2dStaticSprite

by Martin Goran Moravec · in Technical Issues · 03/15/2012 (2:48 am) · 2 replies

Hi,
I've tried recently to convert imagemaps from another project to torque (in attempt to find out how easy it would be to start developing games in Torque 2D using some of our older tools) and I'm a bit of puzzled with the documentation.

I've created a simple static sprite using the editor out of one old texture atlas - where I cut out the proper 1024x614 part of it. It looked as it was supposed to, but after saving I got rather unexpected size value (100,74.832)? What units are used for the size? (and where to look in the documentation for the description of it)

new t2dStaticSprite() {
imageMap = "image_0000_rgbaImageMap";
frame = "0";
useSourceRect = "1";
sourceRect = "0 0 1024 614";
canSaveDynamicFields = "1";
Position = "-0.000 0.000";
size = "100.000 74.832";
mountID = "2";
};

Also the description of the class itself does not contain anything about sourceRect in fact, is it just outdated, or am I just blind? :)

About the author

Recent Threads


#1
03/15/2012 (12:08 pm)
@Martin - The initial size (100.000 74.832) is based on the width and height of the cell used when the sprite is first added to the scene. In your example, that would be frame. So the first cell (frame 0) is 100 x 74.8 pixels, which is the world unit measurement for the engine.

As for sourceRect, it's actually a relatively new feature that slipped through the cracks during the documentation pass. This feature acts like a more traditional texture atlas. From another post:

Quote:
sourceRect: xPixelOffset yPixelOffset pixelWidth pixelHeight;

The width and height are of the cell you wish to cut out of the imageMap, and the x and y offset are offset from the top left corner.

So to break a 32x32 imagemap up into 4 16x16 pieces, here is what you would define sourceRect as for each piece.

Top left corner:
"0 0 16 16"

Top right corner:
"16 0 16 16"

Bottom left corner:
"0 16 16 16"

Bottom right corner:
"16 16 16 16"
#2
04/02/2012 (6:59 am)
Thanks :)
it is surpising that something like source rectangle is so new.