2D Toolkit Forum

2D Toolkit => Support => Topic started by: stevexu on August 23, 2013, 04:08:25 pm

Title: how to get the Anchor of a tk2dSptite
Post 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
Title: Re: how to get the Anchor of a tk2dSptite
Post by: unikronsoftware on August 23, 2013, 04:10:01 pm
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.
Title: Re: how to get the Anchor of a tk2dSptite
Post by: stevexu on August 23, 2013, 04:16:22 pm
 ;)   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;

Title: Re: how to get the Anchor of a tk2dSptite
Post by: unikronsoftware on August 23, 2013, 04:44:50 pm
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.
Title: Re: how to get the Anchor of a tk2dSptite
Post by: stevexu on August 24, 2013, 04:13:51 am
thanks!Maybe  UntrimmedBounds  can help, i will try!