Author Topic: Color tween in code  (Read 3087 times)

Petroz

  • Guest
Color tween in code
« on: May 11, 2012, 06:47:00 AM »
I am trying to use tweens in code. I have discovered TweenColor.Begin. I am using that and it is adding a TweenColor component to my Sprite, but the 'to' and 'from' colors are both white and it seems to have no effect. I am also setting UISprite.color which doesn't seem to be working either. The code I'm using to create the sprite is:

  1.                 indicatorIconInstance.transform.parent = GUIManager.instance().osiPanel.transform;
  2.                 sprite = NGUITools.AddSprite(indicatorIconInstance, GUIManager.instance().atlas, normalSpritName);

I also get a warning:

Quote
You can't place widgets on a layer different than the UIPanel that manages them.
If you want to move widgets to a different layer, parent them to a new panel instead.

Any help would be greatly appreciated.

ArenMook

  • Administrator
  • Hero Member
  • *****
  • Thank You
  • -Given: 337
  • -Receive: 1171
  • Posts: 22,128
  • Toronto, Canada
    • View Profile
Re: Color tween in code
« Reply #1 on: May 11, 2012, 02:38:52 PM »
TweenColor.Begin creates a new tween, letting you specify which color to tween to. The "from" color is the current color of the sprite.

The warning means you are not using the Widget Tool to create your widgets, or that you are adding them to a game object whos layer is different than that of your parent UIPanel. Use NGUI's functionality for everything and you will avoid this problem. Alt+Shift+N adds a new child game object.

Petroz

  • Guest
Re: Color tween in code
« Reply #2 on: May 11, 2012, 07:30:03 PM »
Thanks for the quick reply.

Found my error. I was using color with RGBA values from 0-255 taken from the Color picker, I just realized that the range in for Color is 0-1. Everything is working exactly as expected now.  ;D

I need to create these at run time because there is a dynamic number of them. I managed to fix the warning by setting the GameObject to the same layer as the rest of my UI.