Hello Guest

Author Topic: Scaled TK2DSlicedSprite loses BoxCollider bounds on SpirteChange  (Read 5716 times)

Goepfie

  • 2D Toolkit
  • Newbie
  • *
  • Posts: 9
    • View Profile
Hey,

I am using several SlicedSprites which are dynamically instantiated and manually scaled and positioned. When I change the Sprite using SetSprite( string Name ) it loses its BoxCollider Bounds. At this point the bounds do not change, but I dont know the extents it should have. Is this a Bug or expected behaviour? Currently I circumvent the problem by caching the bounds manually.

Thanks.

unikronsoftware

  • Administrator
  • Hero Member
  • *****
  • Posts: 9709
    • View Profile
Re: Scaled TK2DSlicedSprite loses BoxCollider bounds on SpirteChange
« Reply #1 on: April 04, 2013, 08:31:40 pm »
The behaviour for this has changed in tk2d 1.92.
In 1.92, the collider setting is a property of the sliced / clipped / tiled sprite. As long as it is set to true, it should always update correctly.

What version are you on?

Goepfie

  • 2D Toolkit
  • Newbie
  • *
  • Posts: 9
    • View Profile
Re: Scaled TK2DSlicedSprite loses BoxCollider bounds on SpirteChange
« Reply #2 on: April 08, 2013, 01:48:02 pm »
I am on 1.92 final + patch 1 and Unity 4.1.2. Instantiation is handled through PoolManager 4
CreateBoxCollider is true on the prefab, and the ColliderType in the collection is set to BoxTrimmed.

Currently I set the sprite and collider after instantiation through:

Code: [Select]
((tk2dSlicedSprite)(this.GetComponent<tk2dSlicedSprite>())).scale = new Vector3(xfactor, yfactor, 1);
((BoxCollider)(this.GetComponent<BoxCollider>())).size = new Vector3(width, height, 0.2f);

unikronsoftware

  • Administrator
  • Hero Member
  • *****
  • Posts: 9709
    • View Profile
Re: Scaled TK2DSlicedSprite loses BoxCollider bounds on SpirteChange
« Reply #3 on: April 19, 2013, 12:58:35 pm »
The issue with this is due to "legacy mode". This has been removed in tk2d 2.0, but for now, please set slicedsprite.legacyMode = false; after creating it.