Exemplo n.º 1
0
        public static Tween Create(TweenMode mode, Ease.Easer easer = null, float duration = 1f, bool start = false)
        {
            Tween tween;
            if (cached.Count == 0)
                tween = new Tween();
            else
                tween = cached.Pop();
            tween.OnUpdate = tween.OnComplete = tween.OnStart = null;

            tween.Init(mode, easer, duration, start);
            return tween;
        }
Exemplo n.º 2
0
        public Tween(TweenMode mode, Ease.Easer easer = null, int duration = 1, bool start = false)
            : base(false, false)
        {
            #if DEBUG
            if (duration < 1)
                throw new Exception("Tween duration cannot be less than 1");
            #endif

            Mode = mode;
            Easer = easer;
            Duration = duration;

            Active = false;

            if (start)
                Start();
        }
Exemplo n.º 3
0
 public static Tween Position(Entity entity, Vector2 targetPosition, float duration, Ease.Easer easer, TweenMode tweenMode = TweenMode.Oneshot)
 {
     Vector2 startPosition = entity.Position;
     Tween tween = Tween.Create(tweenMode, easer, duration, true);
     tween.OnUpdate = (t) => { entity.Position = Vector2.Lerp(startPosition, targetPosition, t.Eased); };
     entity.Add(tween);
     return tween;
 }
Exemplo n.º 4
0
        private void Init(TweenMode mode, Ease.Easer easer, float duration, bool start)
        {
            #if DEBUG
            if (duration <= 0)
                throw new Exception("Tween duration cannot be less than zero");
            #else
            if (duration <= 0)
                duration = .000001f;
            #endif

            Mode = mode;
            Easer = easer;
            Duration = duration;

            TimeLeft = 0;
            Percent = 0;
            Active = false;

            if (start)
                Start();
        }
Exemplo n.º 5
0
 public static Tween Set(Entity entity, TweenMode tweenMode, float duration, Ease.Easer easer, Action<Tween> onUpdate, Action<Tween> onComplete = null)
 {
     Tween tween = Tween.Create(tweenMode, easer, duration, true);
     tween.OnUpdate += onUpdate;
     tween.OnComplete += onComplete;
     entity.Add(tween);
     return tween;
 }
Exemplo n.º 6
0
 public static Tween Alpha(GraphicsComponent image, float targetAlpha, int duration, Ease.Easer easer, TweenMode tweenMode = TweenMode.Oneshot)
 {
     Entity entity = image.Entity;
     float startAlpha = image.Color.A / 255;
     Tween tween = new Tween(tweenMode, easer, duration, true);
     tween.OnUpdate = (t) => { image.Color.A = (byte)Math.Round(MathHelper.Lerp(startAlpha, targetAlpha, t.Eased) * 255.0f); };
     entity.Add(tween);
     return tween;
 }
Exemplo n.º 7
0
 public static Tween Set(Entity entity, int duration, Ease.Easer easer, Action<Tween> onUpdate, TweenMode tweenMode = TweenMode.Oneshot)
 {
     Tween tween = new Tween(tweenMode, easer, duration, true);
     tween.OnUpdate += onUpdate;
     entity.Add(tween);
     return tween;
 }
Exemplo n.º 8
0
 public static Tween Scale(GraphicsComponent image, Vector2 targetScale, int duration, Ease.Easer easer, TweenMode tweenMode = TweenMode.Oneshot)
 {
     Vector2 startScale = image.Scale;
     Tween tween = new Tween(tweenMode, easer, duration, true);
     tween.OnUpdate = (t) => { image.Scale = Vector2.Lerp(startScale, targetScale, t.Eased); };
     image.Entity.Add(tween);
     return tween;
 }