Hello Guest

Author Topic: Rightmost Coordinate of a Sprite  (Read 5092 times)

AGP

  • 2D Toolkit
  • Newbie
  • *
  • Posts: 6
    • View Profile
Rightmost Coordinate of a Sprite
« on: April 17, 2012, 08:24:17 pm »
How do I find the rightmost coordinate of a given sprite in worldspace?

AGP

  • 2D Toolkit
  • Newbie
  • *
  • Posts: 6
    • View Profile
Re: Rightmost Coordinate of a Sprite
« Reply #1 on: April 17, 2012, 08:28:34 pm »
float rightMost = src.transform.position + Vector3(src.GetBounds().extents.x, 0, 0) ?

unikronsoftware

  • Administrator
  • Hero Member
  • *****
  • Posts: 9709
    • View Profile
Re: Rightmost Coordinate of a Sprite
« Reply #2 on: April 17, 2012, 11:26:48 pm »
That would be true if the sprite origin was at the center. In the event that it isn't the following will do it

tk2dSprite sprite;
var bounds = sprite.GetUntrimmedBounds();
target.position = sprite.transform.position + new Vector3(bounds.center.x + bounds.extents.x, 0, 0);


Use GetUntrimmedBounds if you want the full bounds of the source texture, use GetBounds if you only care about the visible data.