Getting dimensions of Transform

When a sprite is loaded in a transform, the scene automatically resizes to this picture.
My sprite image is width 720 pixels, height 1260 pixels.
But how can I get these values to use in the control of the transform?
I want to put a label just above the sprite image so when it “talks” the text is just above its “head”.
so I guess I need the Transform.TranslationY + image height?

I have not yet had this need with CGE but with Wintermute and Unity the way has always been this.
If the sprite’s hotspot is in the middle of the feet (as it should be) the balloon should appear in position: character’s y + character’s height + a handful of pixels so that it isn’t attached to the head.
However, some variables must be considered. If the character is at the top of the screen the balloon should appear to the side (otherwise it would not be visible), if the character is on the right or left side of the screen you will have to move the balloon to the left or right respectively. In short, planning to place the balloon above and in the center of the character’s head is not enough. You should always check the position of the character and move the balloon when necessary.

Thanks for the notice. But the first problem is to get to the Y top of the scene or transform.
By default the hotspot of the scene is in the centre / middle of the image and not at the “feet.”
There is no Transform “height” method to the scene so to put Label.Y on top I cannot code something like Label.Y := PlayerTransform. Translation.Y + PlayerTransform. Height;

Have you tried using “BoundingBox”?
If you take a look at the Api reference there are also LocalBoundingBox and WorldBoundingBox.
I don’t know if it’s the right way (we are waiting for someone who knows more) but something like this might work:

var
H: single;

MyLabel.Caption := 'Over the head';
H := MyScene.WorldBoundingBox.SizeY;
MyLabel.Left := MyScene.Translation.X;
MyLabel.Bottom := MyScene.Translation.Y - (H / 2) - 20;

Thanks!
Translation.X works okay for the Label.Left.

Now I tried LocalBoundingBox and WorldBoundingBox and it’s Y size is not the same as the loaded pictureheight;

picture height: 1202 pixels, Boundingbox size: 1176
picture height: 1193 pixels, Boundingbox size: 1154
This is probably because of the UI scaling.

Translation.Y hotspot is in the middle of the scene picture. I added boundingbox.sizeY and the labelcaption was way too high, so I changed it in boundingbox.sizeY/2;
That’s better but not accurate enough and the Y position of the label is different per scene (Translation.Y) so this is strange.

Thanks anyway. The world coordination system is confusing and I am still waiting for help from Michalis on the “setting scene coordinates” topic to set things right. It probably is a camera position thing.

The Scene.LocalBoundingBox.Size.Y should correspond to the vertical size of the frame in the sprite sheet. The UI scaling doesn’t change these values. If it’s not, please submit an example sprite sheet.

The Scene.BoundingBox is Scene.LocalBoundingBox transformed into Scene's parent coordinates (the size should be equal, unless you do some scaling by Scene.Scale).

The Scene.WorldBoundingBox is Scene.LocalBoundingBox transformed into world coordinates (that is, transformed by all TCastleTransform parents, up to the root Viewport.Items).

That being said, remember that vertical sizes of the frame may be different (smaller) from you expected, if you exported them and eliminated whitespace around. E.g. in your other examples, I see you used johnstandidle.starling-xml created by TexturePacker, and each frame has a bit different height:

<TextureAtlas imagePath="johnstandidle.png" width="2317" height="1205">
    <SubTexture name="johnstandfront" x="1" y="1" width="354" height="1177" frameX="-157" frameY="-14" frameWidth="720" frameHeight="1260"/>
    <SubTexture name="johnstandsw" x="357" y="1" width="287" height="1184" frameX="-210" frameY="-22" frameWidth="720" frameHeight="1260"/>
    <SubTexture name="johnstandleft" x="646" y="1" width="198" height="1181" frameX="-274" frameY="-24" frameWidth="720" frameHeight="1260"/>
    <SubTexture name="johnstandnw" x="846" y="1" width="304" height="1187" frameX="-241" frameY="-21" frameWidth="720" frameHeight="1260"/>
    <SubTexture name="johnstandback" x="1152" y="1" width="364" height="1185" frameX="-223" frameY="-15" frameWidth="720" frameHeight="1260"/>
    <SubTexture name="johnstandne" x="1518" y="1" width="311" height="1195" frameX="-242" frameY="-12" frameWidth="720" frameHeight="1260"/>
    <SubTexture name="johnstandright" x="1831" y="1" width="197" height="1203" frameX="-270" frameY="-7" frameWidth="720" frameHeight="1260"/>
    <SubTexture name="johnstandse" x="2030" y="1" width="286" height="1200" frameX="-202" frameY="-10" frameWidth="720" frameHeight="1260"/>
</TextureAtlas>

So frame heights are like 1177, 1184, 1181, … depending on the particular frame.

The engine does not ever see the full height, which I guess could have been 1260.

This is a valid optimization from TexturePacker, but it also means that engine just doesn’t know the value 1260, i.e. we don’t have the information about it ever.

The solution:

  1. use our CGE sprite sheet creator instead, that doesn’t try to conserve whitespace (for now; when it will, there will be a checkbox for that)
  2. or look into TexturePacker settings, there’s most likely a checkbox to turn if off, to not do “whitespace trimming” or such
  3. or just do not depend on scene bounding box, and instead store the value “1260” associated with your character elsewhere, and use it.

Ah, ofcourse. It takes the height of the individual subtextures, which is fine for me, as the heigth sizes are different for every character sprite.

See attachment, this is strange: I use label2 to display the used image height.
The image height of ‘johnstandse’ is 1200 but it displays half of it (600). And so with every other subtexture I try.
Why is it divided by 2?
And in the editor I put label2 under the character, but when I run the code it is placed higher, over the character, so there is something odd.
There are black borders left and right of the background; picture is less width than the viewport. It should fill the whole viewport.
Translation problems.zip (44.9 MB)

Because you scale StandIdleScene by half:

And then you use

Label2.Caption := 'sprite image height: ' + floattostr(PlayerTransform.BoundingBox.SizeY);

If you want to get original size, then get reference to StandIdleScene , and use LocalBoundingBox.SizeY. Like just StandIdleScene.LocalBoundingBox.SizeY.

From what I understand, the rest of this is solved in a new thread Coordinates again .

Ah yes.
This is plain stupid of me.
I have all the underlying scenes for walking directions under Playertransform scaled 1.0 in design, I scaled only the standidle to 0.5 because the original image is 2 times larger (because I want to use zoom effect later, so the image had to be larger while remaining high quality).
:wink: