Hello Guest

Author Topic: [SOLVED] CurrentSprite.GetUntrimmedBounds() Gives wrong center  (Read 5285 times)

yo_milo

  • 2D Toolkit
  • Newbie
  • *
  • Posts: 11
    • View Profile
[SOLVED] CurrentSprite.GetUntrimmedBounds() Gives wrong center
« on: January 12, 2017, 01:24:07 am »
Greetings, I was converting some code that works with spriteRenderers to work with 2D Toolkit, and there was a section of code that read like:
if(bounds.Contains(position) ){
//Do something
}

However, using 2DToolkit sprites, I figured I should use tk2dSprite.CurrentSprite.GetBounds().Contains(position) or tk2tk2dSprite.GetBounds().Contains(Position), but it was giving me false results :(, and I noticed my bounds.Center parameters were always ceros.

Is there anything I am missing? Should I use the MeshRenderer instead? For the moment I decided to store the bounds in a temporary variable, and then assign the center to my sprite.transform.position.

Is there a 2d toolkit built in parameter that gives me the correct bounds?
« Last Edit: January 12, 2017, 07:12:30 pm by yo_milo »

unikronsoftware

  • Administrator
  • Hero Member
  • *****
  • Posts: 9709
    • View Profile
Re: CurrentSprite.GetUntrimmedBounds() Gives wrong center
« Reply #1 on: January 12, 2017, 09:47:14 am »
CurrentSprite.GetBounds returns bounds in local space to the sprite. You should use renderer.bounds, that returns an AABB in world space. I'm assuming your position variable is in world space

yo_milo

  • 2D Toolkit
  • Newbie
  • *
  • Posts: 11
    • View Profile
Re: CurrentSprite.GetUntrimmedBounds() Gives wrong center
« Reply #2 on: January 12, 2017, 07:12:15 pm »
CurrentSprite.GetBounds returns bounds in local space to the sprite. You should use renderer.bounds, that returns an AABB in world space. I'm assuming your position variable is in world space

Thank you, I assumed I had to use the mesh renderer, but initially i thought tk2dsprite had a built in parameters for bounds.

Thank you.