Hello Guest

Author Topic: how to get the Anchor of a tk2dSptite  (Read 6146 times)

stevexu

  • Newbie
  • *
  • Posts: 29
    • View Profile
how to get the Anchor of a tk2dSptite
« 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

unikronsoftware

  • Administrator
  • Hero Member
  • *****
  • Posts: 9709
    • View Profile
Re: how to get the Anchor of a tk2dSptite
« Reply #1 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.

stevexu

  • Newbie
  • *
  • Posts: 29
    • View Profile
Re: how to get the Anchor of a tk2dSptite
« Reply #2 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;


unikronsoftware

  • Administrator
  • Hero Member
  • *****
  • Posts: 9709
    • View Profile
Re: how to get the Anchor of a tk2dSptite
« Reply #3 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.

stevexu

  • Newbie
  • *
  • Posts: 29
    • View Profile
Re: how to get the Anchor of a tk2dSptite
« Reply #4 on: August 24, 2013, 04:13:51 am »
thanks!Maybe  UntrimmedBounds  can help, i will try!