Example #1
0
        private void StartTween()
        {
            from = Position;
            to   = nodes[targetIdx];
            float duration = Vector2.Distance(from, to) / 12f;

            if (selfData.Get <bool>("fastMoving"))
            {
                duration /= 3f;
            }
            Tween tween = Tween.Create(Tween.TweenMode.Looping, Ease.SineInOut, duration, start: true);

            tween.OnUpdate = delegate(Tween t) {
                if (Collidable)
                {
                    MoveTo(Vector2.Lerp(from, to, t.Eased));
                }
                else
                {
                    MoveToNaive(Vector2.Lerp(from, to, t.Eased));
                }
            };
            tween.OnComplete = delegate(Tween t) {
                targetIdx++;
                if (targetIdx >= nodes.Length)
                {
                    targetIdx = 0;
                }
                from = Position;
                to   = nodes[targetIdx];
                selfData.Invoke("set_Duration", Vector2.Distance(from, to) / (selfData.Get <bool>("fastMoving") ?  36f : 12f));
            };
            Add(tween);
        }