Hello Guest

Author Topic: alpha animation  (Read 7163 times)

atmuc

  • 2D Toolkit
  • Newbie
  • *
  • Posts: 35
    • View Profile
alpha animation
« on: September 07, 2012, 12:59:59 pm »
i try to dissolve a text mesh. i set animation keys and i see that color/alpha changes. it doesnt work on scene view. if i change alpha level manually it works on scene view. what is wrong with this? how can i see animation results on scene view?

dotty

  • 2D Toolkit
  • Jr. Member
  • *
  • Posts: 65
    • View Profile
Re: alpha animation
« Reply #1 on: September 07, 2012, 04:19:59 pm »
You might need to commit the change, don't quote me on that though.

MooNiZZ

  • 2D Toolkit
  • Jr. Member
  • *
  • Posts: 63
    • View Profile
Re: alpha animation
« Reply #2 on: September 07, 2012, 04:22:33 pm »
I believe what dotty says is right, after you've made changes in the code, you need to do a .Commit() for it to actually change. Same goes if you change the text.

atmuc

  • 2D Toolkit
  • Newbie
  • *
  • Posts: 35
    • View Profile
Re: alpha animation
« Reply #3 on: September 07, 2012, 05:50:09 pm »
I believe what dotty says is right, after you've made changes in the code, you need to do a .Commit() for it to actually change. Same goes if you change the text.

I dont have any code. I use unity animation system.

unikronsoftware

  • Administrator
  • Hero Member
  • *****
  • Posts: 9709
    • View Profile
Re: alpha animation
« Reply #4 on: September 07, 2012, 06:45:27 pm »
Easy way to do this: write a behaviour which monitors the color / scale and calls Commit if it changes. My main OS SSD has failed, so I can't find this until it is replaced - but if you haven't managed to do it, let me know and I'll post my version once I've recovered my OS.

atmuc

  • 2D Toolkit
  • Newbie
  • *
  • Posts: 35
    • View Profile
Re: alpha animation
« Reply #5 on: September 08, 2012, 11:01:27 am »
Easy way to do this: write a behaviour which monitors the color / scale and calls Commit if it changes. My main OS SSD has failed, so I can't find this until it is replaced - but if you haven't managed to do it, let me know and I'll post my version once I've recovered my OS.

is there any case that i do not want to commit at current frame? if i change something it means i want to see some changes. should not 2dtk apply all changes on update phase? at least there should be autocommit option for unity animation system. cant you run commit as the last command of update method?

atmuc

  • 2D Toolkit
  • Newbie
  • *
  • Posts: 35
    • View Profile
Re: alpha animation
« Reply #6 on: September 08, 2012, 11:46:51 am »
this code works

Code: [Select]
using UnityEngine;
using System.Collections;
using tk2dRuntime;

public class CommitObserver : MonoBehaviour
{
tk2dTextMesh textMesh;
float previousAlphaValue;

void Start ()
{
textMesh = GetComponent<tk2dTextMesh> ();
previousAlphaValue = textMesh.color.a;
}

void Update ()
{
if (textMesh.color.a != previousAlphaValue) {
previousAlphaValue = textMesh.color.a;
textMesh.Commit ();
}
}
}

unikronsoftware

  • Administrator
  • Hero Member
  • *****
  • Posts: 9709
    • View Profile
Re: alpha animation
« Reply #7 on: September 08, 2012, 02:11:01 pm »
The reasons this isn't a toggle on the textmesh/sprite is twofold:

1. Having an Update function increases overhead significantly, so having it only where absolutely necessary is a lot better.

2. The animation system can't update C# properties. For this, in the most trivial case, then a script like this works perfectly, but if you are animating a hierarchical character (eg. a skinned character, or entire UI) then this script is a lot more efficient, as it only has one Update function for all its children.

What I'll be doing -
1. I'll be adding an AutoCommit for usual use cases, i.e. from script. This can be done without an Update function.
2. I'll find this script I wrote and add it to the distribution as in a "Goodies" folder or something like that.