Game Development Community

How to get width of a specific cell?

by Amjad Yahya · in Torque 2D Beginner · 07/02/2013 (6:03 am) · 5 replies

Suppose we have this image asset file that has 3 frames with different widths and heights:

<ImageAsset
    AssetName="font"
    ImageFile="@assetFile=font.png">
	<ImageAsset.Cells>
		<Cell Offset="0 0" Width="27" Height="50"/>
		<Cell Offset="27 0" Width="13" Height="50"/>
		<Cell Offset="40 0" Width="22" Height="50"/>
	</ImageAsset.Cells>
</ImageAsset>

My question is how to get the width and height of the second or third frame (cell)?

#1
07/02/2013 (6:38 am)
Looking at the current code, there does not appear to be a way to get the cell width for an individual cell. Originally, the ImageAsset could only have uniform cells. That meant getCellWidth() would return the same values for all cells.

The ConsoleMethods need to be updated to take a cell index. Could you post that as a GitHub issue, please?
#2
07/02/2013 (7:01 am)
Done. Thanks Mich.
#3
07/02/2013 (12:16 pm)
@Amjad : There you go, you now have functions called

ImageAsset.getExplicitCellWidth(%cellindex)
ImageAsset.getExplicitCellWidth(%cellindex)

I've tested it with several images (most notably images created with TexturePacker) and it works as expected.

You can find the latest development branch with this modification on my personal repository : github.com/capnlove/Torque2D/tree/development

You can also find the pull request to the official repository here :
github.com/GarageGames/Torque2D/pull/88

Give it a go, let me know if it works out for you and we'll push it into the official repository.
#4
07/03/2013 (4:27 am)
Thanks Simon.

I couldn't get it to work because I don't know what to replace "ImageAsset" with! I mean where can I get the Id of an image asset when I load it from a Taml file? I tried adding a "Name" field to the Taml file -generated by texture packer- but that did not work either.
#5
07/04/2013 (9:20 am)
I managed to figure out how to get an assetImage Id from another post here.

%imageAssetId = AssetDatabase.acquireAsset(%sceneObject.Image);
or
%imageAssetId = AssetDatabase.acquireAsset("ToyAssets:font");

getExplicitCellWidth() and getExplicitCellHeight() are working perfectly. Thanks Simon.