public static Storyboard GetAnimation(AnimationDirection? animationDirection, bool isInAnimation, int animationTimeMS, IEasingFunction easingFunction = null)
        {
            var xAxis = "RenderTransform.(TranslateTransform.X)";
            var yAxis = "RenderTransform.(TranslateTransform.Y)";
            var easing = easingFunction != null ? easingFunction : new QuadraticEase();

            var opac = GetOpac(isInAnimation, animationTimeMS);

            var story = new Storyboard();
            (story as IAddChild).AddChild(opac);

            DoubleAnimation anim = null;

            if (animationDirection != null)
            {
                if (isInAnimation)
                {
                    anim = new DoubleAnimation(animationDirection == AnimationDirection.Left || animationDirection == AnimationDirection.Top ? -30 : 30, 0, new Duration(new TimeSpan(0, 0, 0, 0, animationTimeMS))) { EasingFunction = easing };
                }
                else
                {
                    anim = new DoubleAnimation(0, animationDirection == AnimationDirection.Left || animationDirection == AnimationDirection.Top ? -30 : 30, new Duration(new TimeSpan(0, 0, 0, 0, animationTimeMS))) { EasingFunction = easing };
                }

                if (anim != null)
                {
                    anim.SetValue(Storyboard.TargetPropertyProperty, new PropertyPath(animationDirection == AnimationDirection.Left || animationDirection == AnimationDirection.Right ? xAxis : yAxis));
                    (story as IAddChild).AddChild(anim);
                }
            }

            return story;
        }
示例#2
0
 public static AnimationDirection GetOppositeDirection(AnimationDirection direction)
 {
     switch (direction)
     {
         case AnimationDirection.Left:
             return AnimationDirection.Right;
         case AnimationDirection.Right:
             return AnimationDirection.Left;
     }
     return AnimationDirection.Left;
 }
示例#3
0
 public static Vector2 GetFacingFromDirection(AnimationDirection direction)
 {
     switch (direction)
     {
         case AnimationDirection.Right:
             return new Vector2(1f, 0f);
         case AnimationDirection.Left:
             return new Vector2(-1f, 0f);
     }
     return Vector2.Zero;
 }
示例#4
0
        public PlayerEntity(ThrongGameScreen gameScreen, Clip clip,
            Vector2 position, Vector2 scale, float rotation)
            : base(gameScreen, clip, position, scale, rotation, PHYSICS_OFFSET, PHYSICS_RADIUS)
        {
            EntityType = Type.Player;

            _animDirection = AnimationDirection.Right;

            LoadSounds(gameScreen.Content);

            SetupAnimations(clip);

            SwitchToIdle();
        }
        public static Vector2 GetFacingFromDirection(AnimationDirection direction)
        {
            switch (direction)
            {
                case AnimationDirection.Right:
                    return new Vector2(1f, 0f);
                case AnimationDirection.Left:
                    return new Vector2(-1f, 0f);
                case AnimationDirection.Up:
                    return new Vector2(0f, -1f);
                case AnimationDirection.Down:
                    return new Vector2(0f, 1f);

                case AnimationDirection.DiagonalUpLeft:
                    return new Vector2(-1f, -1f);
                case AnimationDirection.DiagonalUpRight:
                    return new Vector2(1f, -1f);
                case AnimationDirection.DiagonalDownLeft:
                    return new Vector2(-1f, 1f);
                case AnimationDirection.DiagonalDownRight:
                    return new Vector2(1f, 1f);
            }
            return Vector2.Zero;
        }
        public static AnimationDirection GetOppositeDirection(AnimationDirection direction)
        {
            switch (direction)
            {
                case AnimationDirection.Left:
                    return AnimationDirection.Right;
                case AnimationDirection.Right:
                    return AnimationDirection.Left;
                case AnimationDirection.Up:
                    return AnimationDirection.Down;
                case AnimationDirection.Down:
                    return AnimationDirection.Up;

                case AnimationDirection.DiagonalUpLeft:
                    return AnimationDirection.DiagonalDownRight;
                case AnimationDirection.DiagonalUpRight:
                    return AnimationDirection.DiagonalDownLeft;
                case AnimationDirection.DiagonalDownLeft:
                    return AnimationDirection.DiagonalUpRight;
                case AnimationDirection.DiagonalDownRight:
                    return AnimationDirection.DiagonalUpLeft;
            }
            return AnimationDirection.Down;
        }
 public void Start()
 {
     animating = true;
     if (isToggle)
     {
         if (currentFrame == 0)
         {
             direcaoDaAnimacao = AnimationDirection.Normal;
         }
         else if (currentFrame == frameCount - 1)
         {
             direcaoDaAnimacao = AnimationDirection.Inversa;
         }
     }
 }
示例#8
0
        //----------------------------------------------------------------------
        void UpdateDirection()
        {
            if( Time >= Delay + Duration )
            {
                switch( Loop )
                {
                    case AnimationLoop.NoLoop:
                        Time = Delay + Duration;
                        break;
                    case AnimationLoop.Loop:
                        Time -= Delay + Duration;
                        break;
                    case AnimationLoop.LoopBackAndForth:
                        Time = (Delay + Duration) - ( Time - (Delay + Duration) );

                        Direction = ( Direction == AnimationDirection.Forward ) ? AnimationDirection.Backward : AnimationDirection.Forward;
                        break;
                }
            }
            else
            if( Time < 0 )
            {
                switch( Loop )
                {
                    case AnimationLoop.NoLoop:
                        Time = 0;
                        break;
                    case AnimationLoop.Loop:
                        Time += Delay + Duration;
                        break;
                    case AnimationLoop.LoopBackAndForth:
                        Time = -Time;
                        Direction = ( Direction == AnimationDirection.Forward ) ? AnimationDirection.Backward : AnimationDirection.Forward;
                        break;
                }
            }
        }
示例#9
0
 /// <summary>
 /// Creates a new <b>FormAnimator</b> object for the specified form using the specified method in the specified direction over the specified duration
 /// </summary>
 /// <param name="form">
 /// The form to be animated
 /// </param>
 /// <param name="method">
 /// The animation method used to show and hide the form
 /// </param>
 /// <param name="direction">
 /// The direction in which to animate the form
 /// </param>
 /// <param name="duration">
 /// The number of milliseconds over which the animation is played
 /// </param>
 /// <remarks>
 /// The <i>direction</i> argument will have no effect if the <b>Center</b> or <b>Fade</b> method is
 /// specified
 /// </remarks>
 public FormAnimator(Form form, AnimationMethod method, AnimationDirection direction, int duration) : this(form, method, duration)
 {
     _direction = direction;
 }
 public void SetDirection(AnimationDirection direction)
 {
     this.playerAnimation.SetFloat("Dir", (float)direction);
 }
        public void StartNewAnimation(AnimationDirection animationDirection, Point animationSource, object[] data = null)
        {
            if (!IsAnimating() || InterruptAnimation)
            {
                if (Singular && animationDirections.Count > 0)
                {
                    animationDirections[0] = animationDirection;
                }
                else
                {
                    animationDirections.Add(animationDirection);
                }

                if (Singular && animationSources.Count > 0)
                {
                    animationSources[0] = animationSource;
                }
                else
                {
                    animationSources.Add(animationSource);
                }

                if (!(Singular && animationProgresses.Count > 0))
                {
                    switch (animationDirections[animationDirections.Count - 1])
                    {
                        case AnimationDirection.InOutRepeatingIn:
                        case AnimationDirection.InOutIn:
                        case AnimationDirection.In:
                            animationProgresses.Add(MIN_VALUE);
                            break;
                        case AnimationDirection.InOutRepeatingOut:
                        case AnimationDirection.InOutOut:
                        case AnimationDirection.Out:
                            animationProgresses.Add(MAX_VALUE);
                            break;
                        default:
                            throw new Exception("Invalid AnimationDirection");
                    }
                }

                if (Singular && animationDatas.Count > 0)
                {
                    animationDatas[0] = data ?? new object[] { };
                }
                else
                {
                    animationDatas.Add(data ?? new object[] { });
                }

            }

            animationTimer.Start();
        }
        public virtual Task HandlePanReset(IEnumerable <View> views, CardsView cardsView, AnimationDirection animationDirection, IEnumerable <View> inactiveViews)
        {
            var view = views.FirstOrDefault();

            if (view == null)
            {
                return(Task.FromResult(true));
            }
            var animTimePercent = 1 - (cardsView.GetSize() - Abs(GetTranslationX(view, cardsView))) / cardsView.GetSize();
            var animLength      = (uint)(AnimationLength * animTimePercent) * 3 / 2;

            if (animLength == 0)
            {
                return(Task.FromResult(true));
            }
            return(new AnimationWrapper(v => SetTranslationX(view, v, cardsView), GetTranslationX(view, cardsView), 0)
                   .Commit(view, nameof(HandlePanApply), 16, animLength, AnimEasing));
        }
        public virtual Task HandleAutoNavigate(IEnumerable <View> views, CardsView cardsView, AnimationDirection animationDirection, IEnumerable <View> inactiveViews)
        {
            var view = views.FirstOrDefault();

            if (view == null)
            {
                return(Task.FromResult(false));
            }

            view.IsVisible = true;
            return(new AnimationWrapper(v => SetTranslationX(view, v, cardsView), GetTranslationX(view, cardsView), 0)
                   .Commit(view, nameof(HandleAutoNavigate), 16, AnimationLength, AnimEasing));
        }
        public override void HandlePanChanged(IEnumerable <View> views, CardsView cardsView, double xPos, AnimationDirection animationDirection, IEnumerable <View> inactiveViews)
        {
            var view = views.FirstOrDefault();

            if (animationDirection == AnimationDirection.Null || view == null)
            {
                HandleInitView(views, cardsView, (AnimationDirection)Sign(GetTranslationX(view)));
                HandleInitView(inactiveViews, cardsView, (AnimationDirection)Sign(GetTranslationX(inactiveViews?.FirstOrDefault())));
                return;
            }

            var step       = GetStep(cardsView);
            var checkValue = Sign((int)animationDirection) * step + xPos;

            if (Abs(checkValue) > step || (animationDirection == AnimationDirection.Prev && checkValue > 0) || (animationDirection == AnimationDirection.Next && checkValue < 0))
            {
                return;
            }

            var otherViews = views.Union(inactiveViews ?? Enumerable.Empty <View>()).Except(Enumerable.Repeat(view, 1));

            ProceedPositionChanged(Sign((int)animationDirection) * step + xPos, view, otherViews, cardsView);
        }
 public void SetDirection(AnimationDirection dir)
 {
     if (currentDirection != dir)
     {
         //douglas - Added this here
         currentDirection = dir; //no need to make it equal outside of if statement
         playerObject.transform.Find("Graphics").localScale =
           new Vector3(playerObject.transform.Find("Graphics").localScale.x * -1,
                       playerObject.transform.Find("Graphics").localScale.y,
                       playerObject.transform.Find("Graphics").localScale.z);
     }
 }
        public override void HandleInitView(IEnumerable <View> views, CardsView cardsView, AnimationDirection animationDirection)
        {
            var index = 0;

            foreach (var view in views ?? Enumerable.Empty <View>())
            {
                ++index;
                if (view == null)
                {
                    continue;
                }
                SetTranslationX(view, Sign((int)animationDirection)
                                * (cardsView.IsRightToLeftFlowDirectionEnabled ? -1 : 1)
                                * GetStep(cardsView)
                                * index, cardsView, true);
            }
        }
        public override Task HandlePanApply(IEnumerable <View> views, CardsView cardsView, AnimationDirection animationDirection, IEnumerable <View> inactiveViews)
        {
            var view = views.FirstOrDefault();

            if (view == null)
            {
                return(Task.FromResult(true));
            }
            var step = GetStep(cardsView);

            var animTimePercent = (step - Abs(GetTranslationX(view))) / step;
            var animLength      = (uint)(AnimationLength * animTimePercent);

            if (animLength == 0)
            {
                return(Task.FromResult(true));
            }

            var otherViews = views.Union(inactiveViews ?? Enumerable.Empty <View>()).Except(Enumerable.Repeat(view, 1));

            return(new AnimationWrapper(v => ProceedPositionChanged(v, view, otherViews, cardsView), GetTranslationX(view), -Sign((int)animationDirection) * step)
                   .Commit(view, nameof(HandlePanReset), 16, animLength, AnimEasing));
        }
示例#18
0
        private static sbyte DrawInternal
        (
            UltimaBatcher2D batcher,
            Mobile owner,
            Item entity,
            int x,
            int y,
            bool mirror,
            sbyte frameIndex,
            bool hasShadow,
            ushort id,
            bool isHuman,
            bool isParent = true,
            bool isMount  = false,
            float alpha   = 0
        )
        {
            if (id >= Constants.MAX_ANIMATIONS_DATA_INDEX_COUNT || owner == null)
            {
                return(0);
            }

            ushort hueFromFile = _viewHue;
            byte   animGroup   = AnimationsLoader.Instance.AnimGroup;

            AnimationDirection direction = AnimationsLoader.Instance.GetBodyAnimationGroup(ref id, ref animGroup, ref hueFromFile, isParent)
                                           .Direction[AnimationsLoader.Instance.Direction];

            AnimationsLoader.Instance.AnimID = id;

            if (direction == null || direction.Address == -1 || direction.FileIndex == -1)
            {
                if (!(_transform && entity == null && !hasShadow))
                {
                    return(0);
                }
            }

            if (direction == null || (direction.FrameCount == 0 || direction.Frames == null) && !AnimationsLoader.Instance.LoadDirectionGroup(ref direction))
            {
                if (!(_transform && entity == null && !hasShadow))
                {
                    return(0);
                }
            }

            if (direction == null)
            {
                return(0);
            }

            direction.LastAccessTime = Time.Ticks;

            int fc = direction.FrameCount;

            if (fc > 0 && frameIndex >= fc || frameIndex < 0)
            {
                frameIndex = 0;
            }

            if (frameIndex < direction.FrameCount)
            {
                AnimationFrameTexture frame = direction.Frames[frameIndex];

                if (frame == null || frame.IsDisposed)
                {
                    if (!(_transform && entity == null && !hasShadow))
                    {
                        return(0);
                    }

                    goto SKIP;
                }

                frame.Ticks = Time.Ticks;

                if (mirror)
                {
                    x -= frame.Width - frame.CenterX;
                }
                else
                {
                    x -= frame.CenterX;
                }

                y -= frame.Height + frame.CenterY;

SKIP:

                if (hasShadow)
                {
                    batcher.DrawSpriteShadow(frame, x, y, mirror);
                }
                else
                {
                    ushort hue        = _viewHue;
                    bool   partialHue = false;

                    if (hue == 0)
                    {
                        hue        = entity?.Hue ?? owner.Hue;
                        partialHue = !isMount && entity != null && entity.ItemData.IsPartialHue;

                        if ((hue & 0x8000) != 0)
                        {
                            partialHue = true;
                            hue       &= 0x7FFF;
                        }

                        if (hue == 0)
                        {
                            hue = hueFromFile;

                            if (hue == 0 && _equipConvData.HasValue)
                            {
                                hue = _equipConvData.Value.Color;
                            }

                            partialHue = false;
                        }
                    }

                    ResetHueVector();
                    ShaderHueTranslator.GetHueVector(ref HueVector, hue, partialHue, alpha);

                    if (_transform)
                    {
                        const float UPPER_BODY_RATIO = 0.35f;
                        const float MID_BODY_RATIO   = 0.60f;
                        const float LOWER_BODY_RATIO = 0.94f;

                        if (entity == null && isHuman)
                        {
                            int frameHeight = frame?.Height ?? 61;
                            _characterFrameStartY = y - (frame != null ? 0 : frameHeight - SIT_OFFSET_Y);
                            _characterFrameHeight = frameHeight;
                            _startCharacterWaistY = (int)(frameHeight * UPPER_BODY_RATIO) + _characterFrameStartY;
                            _startCharacterKneesY = (int)(frameHeight * MID_BODY_RATIO) + _characterFrameStartY;
                            _startCharacterFeetY  = (int)(frameHeight * LOWER_BODY_RATIO) + _characterFrameStartY;

                            if (frame == null)
                            {
                                return(0);
                            }
                        }

                        float h3mod = UPPER_BODY_RATIO;
                        float h6mod = MID_BODY_RATIO;
                        float h9mod = LOWER_BODY_RATIO;


                        if (entity != null)
                        {
                            float itemsEndY = y + frame.Height;

                            if (y >= _startCharacterWaistY)
                            {
                                h3mod = 0;
                            }
                            else if (itemsEndY <= _startCharacterWaistY)
                            {
                                h3mod = 1.0f;
                            }
                            else
                            {
                                float upperBodyDiff = _startCharacterWaistY - y;
                                h3mod = upperBodyDiff / frame.Height;

                                if (h3mod < 0)
                                {
                                    h3mod = 0;
                                }
                            }


                            if (_startCharacterWaistY >= itemsEndY || y >= _startCharacterKneesY)
                            {
                                h6mod = 0;
                            }
                            else if (_startCharacterWaistY <= y && itemsEndY <= _startCharacterKneesY)
                            {
                                h6mod = 1.0f;
                            }
                            else
                            {
                                float midBodyDiff;

                                if (y >= _startCharacterWaistY)
                                {
                                    midBodyDiff = _startCharacterKneesY - y;
                                }
                                else if (itemsEndY <= _startCharacterKneesY)
                                {
                                    midBodyDiff = itemsEndY - _startCharacterWaistY;
                                }
                                else
                                {
                                    midBodyDiff = _startCharacterKneesY - _startCharacterWaistY;
                                }

                                h6mod = h3mod + midBodyDiff / frame.Height;

                                if (h6mod < 0)
                                {
                                    h6mod = 0;
                                }
                            }


                            if (itemsEndY <= _startCharacterKneesY)
                            {
                                h9mod = 0;
                            }
                            else if (y >= _startCharacterKneesY)
                            {
                                h9mod = 1.0f;
                            }
                            else
                            {
                                float lowerBodyDiff = itemsEndY - _startCharacterKneesY;
                                h9mod = h6mod + lowerBodyDiff / frame.Height;

                                if (h9mod < 0)
                                {
                                    h9mod = 0;
                                }
                            }
                        }

                        batcher.DrawCharacterSitted(frame, x, y, mirror, h3mod, h6mod, h9mod, ref HueVector);
                    }
                    else if (frame != null)
                    {
                        batcher.DrawSprite(frame, x, y, mirror, ref HueVector);

                        int yy = -(frame.Height + frame.CenterY + 3);
                        int xx = -frame.CenterX;

                        if (mirror)
                        {
                            xx = -(frame.Width - frame.CenterX);
                        }

                        if (xx < owner.FrameInfo.X)
                        {
                            owner.FrameInfo.X = xx;
                        }

                        if (yy < owner.FrameInfo.Y)
                        {
                            owner.FrameInfo.Y = yy;
                        }

                        if (owner.FrameInfo.Width < xx + frame.Width)
                        {
                            owner.FrameInfo.Width = xx + frame.Width;
                        }

                        if (owner.FrameInfo.Height < yy + frame.Height)
                        {
                            owner.FrameInfo.Height = yy + frame.Height;
                        }
                    }

                    if (frame.Contains(mirror ? x + frame.Width - SelectedObject.TranslatedMousePositionByViewport.X : SelectedObject.TranslatedMousePositionByViewport.X - x, SelectedObject.TranslatedMousePositionByViewport.Y - y))
                    {
                        SelectedObject.Object = owner;
                    }

                    if (entity != null && entity.ItemData.IsLight)
                    {
                        Client.Game.GetScene <GameScene>()
                        .AddLight(owner, entity, mirror ? x + frame.Width : x, y);
                    }
                }

                return(AnimationsLoader.Instance.DataIndex[id]
                       .MountedHeightOffset);
            }

            return(0);
        }
        public virtual void HandlePanChanged(IEnumerable <View> views, CardsView cardsView, double xPos, AnimationDirection animationDirection, IEnumerable <View> inactiveViews)
        {
            var view         = views.FirstOrDefault();
            var inactiveView = inactiveViews.FirstOrDefault();

            if (view != null)
            {
                view.IsVisible = true;
            }
            if (inactiveView != null)
            {
                inactiveView.IsVisible = false;
            }

            if (Abs(xPos) > cardsView.GetSize() || (animationDirection == AnimationDirection.Prev && xPos < 0) || (animationDirection == AnimationDirection.Next && xPos > 0))
            {
                return;
            }

            if (animationDirection == AnimationDirection.Null)
            {
                xPos = Sign(xPos) * Min(Abs(xPos / 4), NoItemMaxPanDistance);
            }

            SetTranslationX(view, xPos, cardsView);
        }
示例#20
0
        /// <summary>
        /// 播放动画片段
        /// </summary>
        /// <param name="anim"></param>
        /// <param name="name"></param>
        /// <param name="dir"></param>
        /// <returns></returns>
        public static AnimationState PlayAnimation(Animation anim, string name, AnimationDirection dir)
        {
            if (string.IsNullOrEmpty(name)) name = anim.clip.name;
            var state = anim[name];
            if (state)
            {
                float speed = state.speed;
                if (dir == AnimationDirection.Toggle)
                {
                    if (speed > 0 && state.time == 0 )
                        dir = AnimationDirection.Reverse;
                    else
                        dir = AnimationDirection.Forward;
                }

                if (dir == AnimationDirection.Reverse && state.time == 0f)
                {
                    state.time = state.length;
                }
                else if (dir == AnimationDirection.Forward && state.time == state.length)
                {
                    state.time = 0f;
                }

                state.speed = Mathf.Abs(speed) * (int)dir;

                anim.Play(name);
                anim.Sample();
            }
            return state;
        }
示例#21
0
 public AnimKey(State state, Weapon weapon, AnimationDirection direction)
 {
     State = state;
     Weapon = weapon;
     Direction = direction;
 }
示例#22
0
        /// <summary>
        /// 播放动画片段
        /// </summary>
        /// <param name="anim"></param>
        /// <param name="name"></param>
        /// <param name="dir"></param>
        /// <returns></returns>
        public static AnimatorStateInfo PlayAnimator(Animator anim, string name, AnimationDirection dir)
        {
            var state = anim.GetCurrentAnimatorStateInfo (0);
            float speed = anim.GetFloat("speed");
            float normalizedTime = 1;
            if (dir == AnimationDirection.Toggle)
            {
                if (speed > 0)
                    dir = AnimationDirection.Reverse;
                else
                    dir = AnimationDirection.Forward;
            }

            if (dir == AnimationDirection.Reverse)
            {
                anim.SetFloat("speed", -1 * Mathf.Abs(speed));
                normalizedTime = 1;
            }
            else if (dir == AnimationDirection.Forward )
            {
                anim.SetFloat("speed", Mathf.Abs(speed));
                normalizedTime = 0;
            }

            if (!string.IsNullOrEmpty(name))
                anim.Play(name,0,normalizedTime);
            else
                anim.Play (state.fullPathHash,0,normalizedTime);

            return state;
        }
		public void Play(AnimationBehaviour behaviour, AnimationDirection direction, int loopCount)
		{
			throw new NotImplementedException();
		}
示例#24
0
    /// <summary>
    /// Запустить анимацию движения элемента.
    /// </summary>
    /// <param name="direction">Направление движения.</param>
    private void PlayAnimationMove(AnimationDirection direction)
    {
        if (_animation == null)
            return;

        var str = string.Empty;
        switch (direction)
        {
            case AnimationDirection.Up:
                str = AnimationNames.MoveUp;
                break;
            case AnimationDirection.Right:
                str = AnimationNames.MoveRight;
                break;
            case AnimationDirection.Down:
                str = AnimationNames.MoveDown;
                break;
            case AnimationDirection.Left:
                str = AnimationNames.MoveLeft;
                break;
        }
        if (!string.IsNullOrEmpty(str))
            _animation.Play(str);
    }
 public void StartNewAnimation(AnimationDirection animationDirection, object[] data = null)
 {
     StartNewAnimation(animationDirection, new Point(0, 0), data);
 }
示例#26
0
 public AnimKey(State state, AnimationDirection direction)
 {
     State = state;
     Direction = direction;
 }
        public void SetDirection(AnimationDirection direction)
        {
            if (!Singular)
                throw new Exception("Animation is not set to Singular.");

            if (animationProgresses.Count == 0)
                throw new Exception("Invalid animation");

            animationDirections[0] = direction;
        }
示例#28
0
 public void Play(AnimationBehaviour behaviour, AnimationDirection direction, int loopCount)
 {
 }
示例#29
0
 public AnimationParams(AnimationMethod method,
     AnimationDirection direction)
 {
     Method = method;
     Direction = direction;
     Duration = DEFAULT_DURATION;
 }
示例#30
0
 public void StartNewAnimation(AnimationDirection animationDirection, object[] data = null)
 {
     StartNewAnimation(animationDirection, new Point(0, 0), data);
 }
示例#31
0
        void SetCurrentDirection()
        {
            Tweak.Stats = "";
            Tweak.Stats += "_animDirection: " + _animDirection.ToString() + "\r\n";
            Tweak.Stats += "_movementDirection: " + _movementDirection.ToString() + "\r\n";

            if (_movementDirection != Vector2.Zero)
            {
                // Get direction we are pushing
                AnimationDirection newDirection = DirectionHelper.GetDirectionFromHeading(_movementDirection);
                if (newDirection == _animDirection)
                    return;

                if (newDirection == DirectionHelper.GetOppositeDirection(_animDirection))
                {
                    // If pushing in the opposite direction to current facing, change instantly
                    _animDirection = newDirection;
                    PlayNewCharacterAnimation();
                }
                else
                {
                    // Only change when our heading when velocity starts moving slightly towards our heading
                    Vector2 velocity = DynamicBody.LinearVelocity;
                    if (velocity.LengthSquared() < 0.01f)
                        return;

                    Vector2 normalHeading = Vector2.Normalize(_movementDirection);
                    Vector2 normalVelocity = Vector2.Normalize(velocity);
                    float directionDotProduct = Vector2.Dot(normalHeading, normalVelocity);
                    if (directionDotProduct > DIRECTION_CHANGE_THRESHOLD)
                    {
                        _animDirection = newDirection;
                        PlayNewCharacterAnimation();
                    }
                }
            }
        }
示例#32
0
 public AnimationParams(AnimationMethod method,
     AnimationDirection direction,
     int duration)
     : this(method, direction)
 {
     Duration = duration;
 }
示例#33
0
        private static Vector2 handleKeyboardMovement(KeyboardState keystate)
        {
            Vector2 keyMovement = Vector2.Zero;

            if (keystate.IsKeyDown(Keys.W))
            {
                CurrentAnimationDirection = AnimationDirection.Backward;
                keyMovement.Y--;
            }
            if (keystate.IsKeyDown(Keys.S))
            {
                CurrentAnimationDirection = AnimationDirection.Forward;
                keyMovement.Y++;
            }
            if (keystate.IsKeyDown(Keys.A))
            {
                CurrentAnimationDirection = AnimationDirection.Left;
                keyMovement.X--;
            }
            if (keystate.IsKeyDown(Keys.D))
            {
                CurrentAnimationDirection = AnimationDirection.Right;
                keyMovement.X++;
            }
            return keyMovement;
        }
 public void SetDirection(AnimationDirection dir)
 {
     if(currentDirection != dir)
     {
         switchOrientation = true;
     }
     currentDirection = dir;
 }
示例#35
0
 public void Play(AnimationBehaviour behaviour, AnimationDirection direction)
 {
 }
    // Use this for initialization
    void Start()
    {
        gameStateManagerRef = gameObject.GetComponent<GameStateManager>();
        inputManagerRef = gameObject.GetComponent<InputManager>();

        // by default, player should be facing right
        // since we typically start from the left and head right
        currentDirection = AnimationDirection.RIGHT;

        List<Texture2D> walkList = new List<Texture2D>();
        PopulateWalkAnimations(walkList);
        walkAnimation = new Animation(walkList, Animation.AnimationState.WALK);

        List<Texture2D> idleList = new List<Texture2D>();
        PopulateIdleAnimations(idleList);
        idleAnimation = new Animation(idleList, Animation.AnimationState.IDLE);

        List<Texture2D> standList = new List<Texture2D>();
        PopulateStandAnimations(standList);
        standAnimation = new Animation(standList, Animation.AnimationState.STAND);

        List<Texture2D> jumpList = new List<Texture2D>();
        PopulateJumpAnimations(jumpList);
        jumpAnimation = new Animation(jumpList, Animation.AnimationState.JUMP);

        allAnimations.Add(walkAnimation);
        allAnimations.Add(standAnimation);
        allAnimations.Add(idleAnimation);

        currFrame = 0;
        timeToWait = 1 / FPS;

        currentAnim = standAnimation;
    }
示例#37
0
        void UpdateDirectionBasedOnVelocity()
        {
            if (_heading.LengthSquared() > 0.001f)
            {
                // Get direction enemy is moving
                AnimationDirection newDirection = DirectionHelper.GetDirectionFromHeadingBiasHorizontal(_heading, 0.2f);
                if (newDirection == _animDirection)
                    return;

                if (newDirection == DirectionHelper.GetOppositeDirection(_animDirection))
                {
                    // If moving in the opposite direction to current facing, change instantly
                    _animDirection = newDirection;
                    PlayNewEnemyAnimation();
                }
                else
                {
                    // Only change when our heading when velocity starts moving slightly towards our heading
                    Vector2 velocity = DynamicBody.LinearVelocity;
                    if (velocity.LengthSquared() < 0.1f)
                        return;

                    // Avoid flickering
                    Vector2 normalHeading = Vector2.Normalize(_heading);
                    Vector2 normalVelocity = Vector2.Normalize(velocity);
                    float directionDotProduct = Vector2.Dot(normalHeading, normalVelocity);
                    if (directionDotProduct > DIRECTION_CHANGE_THRESHOLD)
                    {
                        _animDirection = newDirection;
                        PlayNewEnemyAnimation();
                    }
                }
            }
        }
示例#38
0
            public AnimKey(State state, AnimationDirection direction)
            {
                switch (state)
                {
                    case EnemyEntity.State.BeingSuckedIn:
                        AnimState = EnemyEntity.AnimState.Sucked;
                        break;
                    case EnemyEntity.State.Retreating:
                    case EnemyEntity.State.WanderAimless:
                    case EnemyEntity.State.WanderTowards:
                    case EnemyEntity.State.Attacking:
                    default:
                        AnimState = EnemyEntity.AnimState.Walk;
                        break;
                }

                Direction = direction;
            }
示例#39
0
 //
 /// ----------------------------------------------------------------------------- 
 /// <summary> 
 /// Creates a new FormAnimator object for the specified form using the specified 
 /// method in the specified direction over the specified duration. 
 /// </summary> 
 /// <param name="form"> 
 /// The form to be animated. 
 /// </param> 
 /// <param name="method"> 
 /// The animation method used to show and hide the form. 
 /// </param> 
 /// <param name="direction"> 
 /// The direction in which to animate the form. 
 /// </param> 
 /// <param name="duration"> 
 /// The number of milliseconds over which the animation is played. 
 /// </param> 
 /// <remarks> 
 /// The direction argument will have no effect if the Centre or Blend method is 
 /// specified. 
 /// </remarks> 
 /// <history> 
 /// [John] 5/09/2005 Created 
 /// </history> 
 /// ----------------------------------------------------------------------------- 
 public FormAnimator(Form form, AnimationMethod method, AnimationDirection direction, int duration)
     : this(form, method, duration)
 {
     this.m_Direction = direction;
 }
        public virtual void HandleInitView(IEnumerable <View> views, CardsView cardsView, AnimationDirection animationDirection)
        {
            var view = views.FirstOrDefault();

            SetTranslationX(view, 0, cardsView, true);
        }