Hello Guest

Author Topic: Setting a tk2dSprite scale in scripting  (Read 7619 times)

nicktp491

  • 2D Toolkit
  • Newbie
  • *
  • Posts: 17
    • View Profile
Setting a tk2dSprite scale in scripting
« on: September 01, 2013, 03:34:18 am »
Honestly I've been trying to figure this out for days with no luck.  All I wanted to do was change the scale of a sprite while the game is running, but it seems that once the game is running the transform scale of the gameObject are set as they are.  I've tried changing the localScale the lossyScale by using .Set and nothing changes during the game.  I know the values are changing but the image itself stays the same.  Any help is thanked for in advance.

profanicus

  • 2D Toolkit
  • Full Member
  • *
  • Posts: 167
    • View Profile
Re: Setting a tk2dSprite scale in scripting
« Reply #1 on: September 01, 2013, 05:03:27 am »
Don't use the transform, use the scale property on the tk2dSprite class.

unikronsoftware

  • Administrator
  • Hero Member
  • *****
  • Posts: 9709
    • View Profile
Re: Setting a tk2dSprite scale in scripting
« Reply #2 on: September 01, 2013, 01:22:34 pm »
You can (and probably should) use the scale property on the tk2dSprite class.
But if you're changing transform.localScale and it isn't physically changing scale... do you have "static" ticked on it or the parent? Thats the only thing I can think of that could cause this...

nicktp491

  • 2D Toolkit
  • Newbie
  • *
  • Posts: 17
    • View Profile
Re: Setting a tk2dSprite scale in scripting
« Reply #3 on: September 01, 2013, 07:18:37 pm »
Don't use the transform, use the scale property on the tk2dSprite class.
I've seen the tk2dSprite class but I am unsure how to call from it because I am using a different script that I attached to the object.

You can (and probably should) use the scale property on the tk2dSprite class.
But if you're changing transform.localScale and it isn't physically changing scale... do you have "static" ticked on it or the parent? Thats the only thing I can think of that could cause this...
That is what I was using and it wasn't changing the scale. Although if I used Debug.Log() to check the value, it was changing just not showing the change on the object.  Also I don't have static checked on the object.

profanicus

  • 2D Toolkit
  • Full Member
  • *
  • Posts: 167
    • View Profile
Re: Setting a tk2dSprite scale in scripting
« Reply #4 on: September 01, 2013, 11:53:46 pm »
Don't use the transform, use the scale property on the tk2dSprite class.
I've seen the tk2dSprite class but I am unsure how to call from it because I am using a different script that I attached to the object.

It's like anything in Unity where you need a script to talk to another component, either use GetComponent in your script or make a variable that you can drag-and-drop the sprite onto in the inspector. See the Unity docs for details.

c# example of getting the sprite component and changing the scale to 2:
Code: [Select]
tk2dSprite sprite;
sprite = GetComponent<tk2dSprite>();
sprite.scale = new Vector3 (2,2,2);

But as Unikron said, changing the scale on the transform should work. You will most likely need to attach an example so someone can check it out and see what is wrong.

nicktp491

  • 2D Toolkit
  • Newbie
  • *
  • Posts: 17
    • View Profile
Re: Setting a tk2dSprite scale in scripting
« Reply #5 on: September 03, 2013, 01:40:46 am »
Don't use the transform, use the scale property on the tk2dSprite class.
I've seen the tk2dSprite class but I am unsure how to call from it because I am using a different script that I attached to the object.

It's like anything in Unity where you need a script to talk to another component, either use GetComponent in your script or make a variable that you can drag-and-drop the sprite onto in the inspector. See the Unity docs for details.

c# example of getting the sprite component and changing the scale to 2:
Code: [Select]
tk2dSprite sprite;
sprite = GetComponent<tk2dSprite>();
sprite.scale = new Vector3 (2,2,2);

But as Unikron said, changing the scale on the transform should work. You will most likely need to attach an example so someone can check it out and see what is wrong.

Yes this helped a lot I was able to get it working after changing around a few variables in my code.  Thank everyone for posting to help me with me scripting problem.