2D Toolkit Forum
2D Toolkit => Support => Topic started by: stevexu on August 23, 2013, 04:08:25 pm
-
how to get the Anchor of a tk2dSprite in a sprite collection? as shown in below image
-
You cant, as you can set the anchor to anything.
Why do you need that information? Most of the time you can simply work around it using the bounds.
-
;) so quickly reply!!!
I want to add a cube to the left of the tk2dSprite, if the Anchor is middle center, then i add like this:
cube = new cube;
cube . x = transform.position.x - bound.x / 2f;
if the Anchor is low leftr, then the cube. x should be transform.position.x;
-
Ah but thats the point you don't need to know what the anchor is.
Bounds b = sprite.GetUntrimmedBounds();
cube.position = sprite.transform.position + b.center - b.size * 0.5f; // lower left
Or something like that.
-
thanks!Maybe UntrimmedBounds can help, i will try!