2D Toolkit Forum

2D Toolkit => Support => Topic started by: lazypeon on May 05, 2013, 06:46:18 pm

Title: SlicedSprite and UIScaleButton -- won't scale from center anchor point?
Post by: lazypeon on May 05, 2013, 06:46:18 pm
Just curious if there is an easy way to fix this issue.  Applying a UIScaleButton to a sprite and clicking it in the Game View properly scales the button as you'd expect (from the center, assuming your anchor point for the sprite is set up for the center).

When applying a UIScaleButton to a SlicedSprite, the anchor appears to always be in the lower left, not in middle.

Is it possible to easily correct this?  I've seen similar questions asked, and it was suggested that the user create a parent GameObject and scale that.  I can definitely do that, but was wondering if there was a 'simpler' solution and/or if this behavior is intentional.
Title: Re: SlicedSprite and UIScaleButton -- won't scale from center anchor point?
Post by: unikronsoftware on May 05, 2013, 07:27:29 pm
What is the anchor point set on the sliced sprite?
The sliced sprite anchor mode overrides the sprite collection setting.

It will always scale from the origin of the mesh, wherever that may be.
In the unity editor, switch tool mode to "Pivot" and space to "Local" to see where the origin really is. You've likely got it set to center, and its always showing the widget at the center.
Title: Re: SlicedSprite and UIScaleButton -- won't scale from center anchor point?
Post by: lazypeon on May 05, 2013, 08:31:08 pm
Doh!  Completely missed the anchor point attribute on the Sliced Sprite; I assumed it would take the anchor point of the sprite collection.  Works as expected now.

Many thanks for the quick response, I appreciate it!
Title: Re: SlicedSprite and UIScaleButton -- won't scale from center anchor point?
Post by: wtg on May 07, 2013, 07:10:06 pm
I'm trying to see if I can use a Sliced Sprite as a button with up an down states. I tried creating a normal sliced sprite and then applied the tk2DButton script but the states become frozen and the button is no longer clickable. I searched the forum and found this thread but I'm unable to setup it properly to see if this is what I'm looking for. Do you have an example of how to set it up right? I basically need to be able to create Sliced Sprites as buttons.
Title: Re: SlicedSprite and UIScaleButton -- won't scale from center anchor point?
Post by: unikronsoftware on May 07, 2013, 09:42:05 pm
Should work fine. Isn't this just failing because your collider is too large? Try making the boxcollider depth a lot less. Like 0.0001 and see what happens.
Title: Re: SlicedSprite and UIScaleButton -- won't scale from center anchor point?
Post by: wtg on May 07, 2013, 10:18:06 pm
Hmm, maybe I did it wrong the first time. I just did it again and it works. Thanks.