2D Toolkit Forum

2D Toolkit => Support => Topic started by: Xaron on August 23, 2016, 07:17:42 pm

Title: Clipped Sprite setting new width doesn't work for me
Post by: Xaron on August 23, 2016, 07:17:42 pm
Hey there,

using Unity 5.4 I try to do some kind of a progress bar and use a clipped sprite for it. Setting it in the editor works perfectly, but not via code:

Start method:
Code: [Select]
_sprite = GetComponent<tk2dClippedSprite>();

Update method:
Code: [Select]
_sprite.SetSprite( "repairing-bar" );
_sprite.clipTopRight.Set( 0.5f, 1.0f );
Debug.Log( _sprite._clipTopRight.x );

_sprite.ClipRect.Set( 0.0f, 0.0f, 0.5f, 1.0f ); doesn't work either...

The editor and debug log both show still 1.0 for the x value (width here) which should be 0.5. I tried ForceBuild() as well but no change. Obviously I'm doing something wrong here?

Thanks!

edit: Well ya got it. My fault. Doing:
Code: [Select]
_sprite.clipTopRight = new Vector2( 0.5f, 1.0f );

is obviously the right thing to do here!
Title: Re: Clipped Sprite setting new width doesn't work for me
Post by: unikronsoftware on August 24, 2016, 11:04:54 am
_sprite.clipTopRight is a property returning a struct, which means that calling Set on it will have no effect as you have found.
You will need to assign a new Vector2 to it.