2D Toolkit Forum

2D Toolkit => Support => Topic started by: AGP on April 17, 2012, 08:24:17 pm

Title: Rightmost Coordinate of a Sprite
Post by: AGP on April 17, 2012, 08:24:17 pm
How do I find the rightmost coordinate of a given sprite in worldspace?
Title: Re: Rightmost Coordinate of a Sprite
Post by: AGP on April 17, 2012, 08:28:34 pm
float rightMost = src.transform.position + Vector3(src.GetBounds().extents.x, 0, 0) ?
Title: Re: Rightmost Coordinate of a Sprite
Post by: unikronsoftware 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.