コード例 #1
0
        /// <summary>
        /// Begins or continues playback of an animation.
        /// </summary>
        public void PlayAnimation(List<Sequence> lsequence, StateElement stateElement)
        {
            StatePlayerElement statePlayerElement = default(StatePlayerElement);
            StateTileElement stateTileElement = default(StateTileElement);
            string stateName = string.Empty;

            if (object.ReferenceEquals(typeof(StatePlayerElement), stateElement.GetType()))
            {
                statePlayerElement = (StatePlayerElement)stateElement;
                stateName = statePlayerElement.state.ToString();
                StateName = stateName;
            }
            else if (object.ReferenceEquals(typeof(StateTileElement), stateElement.GetType()))
            {
                stateTileElement = (StateTileElement)stateElement;
                stateName = stateTileElement.state.ToString();
                StateName = stateName;
            }
            else
            {
                stateName = stateElement.state.ToString();
                StateName = stateName;
            }

            // Start the new animation.
            if (stateElement.Priority == Enumeration.PriorityState.Normal & this.IsStoppable == false)
            {
                return;
            }

            //Check if the animation is already playing
            if (sequence != null && sequence.name == stateName)
            {
                return;
            }

            this.lsequence = lsequence;
            //Search in the sequence the right type
            Sequence result = lsequence.Find((Sequence s) => s.name == stateName.ToUpper());

            if (result == null)
            {
                //will be an error
                return;
            }

            //cloning for avoid reverse pemanently...
            sequence = result;

            if (stateElement.Stoppable != null)
            {
                foreach (Frame f in sequence.frames)
                {
                    f.stoppable = Convert.ToBoolean(stateElement.Stoppable);
                }
            }

            //For increase offset depend of the state previus; for example when running and fall the x offset will be increase.
            if (stateElement.OffSet != Vector2.Zero)
            {
                foreach (Frame f in sequence.frames)
                {
                    f.xOffSet = f.xOffSet + Convert.ToInt32(Math.Truncate(stateElement.OffSet.X));
                    f.yOffSet = f.yOffSet + Convert.ToInt32(Math.Truncate(stateElement.OffSet.Y));
                }
            }

            //Check if reverse movement and reverse order and sign x,y
            if (stateElement.Reverse == Enumeration.SequenceReverse.Reverse)
            {
                List<Frame> newListFrame = new List<Frame>();
                List<Frame> newListCommand = new List<Frame>();

                foreach (Frame f in sequence.frames)
                {
                    if (f.type == Enumeration.TypeFrame.COMMAND)
                    {
                        newListCommand.Add(f);
                    }
                    else
                    {
                        f.xOffSet = -1 * f.xOffSet;
                        f.yOffSet = -1 * f.yOffSet;
                        newListFrame.Add(f);
                    }
                }
                newListFrame.Reverse();
                //add command
                foreach (Frame f in newListCommand)
                {
                    newListFrame.Add(f);
                }

                sequence.frames = newListFrame;
            }

            if (stateElement.Reverse == Enumeration.SequenceReverse.FixFrame)
            {
                this.m_frameIndex = this.FrameSpriteCount() - this.m_frameIndex;
            }
            else
            {
                this.m_frameIndex = 0;
            }

            this.firstTime = true;
        }
コード例 #2
0
        /// <summary>
        /// Begins or continues playback of an animation.
        /// </summary>
        public void PlayAnimation(List <Sequence> lsequence, StateElement stateElement)
        {
            StatePlayerElement statePlayerElement = default(StatePlayerElement);
            StateTileElement   stateTileElement   = default(StateTileElement);
            string             stateName          = string.Empty;

            if (object.ReferenceEquals(typeof(StatePlayerElement), stateElement.GetType()))
            {
                statePlayerElement = (StatePlayerElement)stateElement;
                stateName          = statePlayerElement.state.ToString();
                StateName          = stateName;
            }
            else if (object.ReferenceEquals(typeof(StateTileElement), stateElement.GetType()))
            {
                stateTileElement = (StateTileElement)stateElement;
                stateName        = stateTileElement.state.ToString();
                StateName        = stateName;
            }
            else
            {
                stateName = stateElement.state.ToString();
                StateName = stateName;
            }

            // Start the new animation.
            if (stateElement.Priority == Enumeration.PriorityState.Normal & this.IsStoppable == false)
            {
                return;
            }

            //Check if the animation is already playing
            if (sequence != null && sequence.name == stateName)
            {
                return;
            }



            this.lsequence = lsequence;
            //Search in the sequence the right type
            Sequence result = lsequence.Find((Sequence s) => s.name == stateName.ToUpper());

            if (result == null)
            {
                //will be an error
                return;
            }

            //cloning for avoid reverse pemanently...
            sequence = result;

            if (stateElement.Stoppable != null)
            {
                foreach (Frame f in sequence.frames)
                {
                    f.stoppable = Convert.ToBoolean(stateElement.Stoppable);
                }
            }

            //For increase offset depend of the state previus; for example when running and fall the x offset will be increase.
            if (stateElement.OffSet != Vector2.Zero)
            {
                foreach (Frame f in sequence.frames)
                {
                    f.xOffSet = f.xOffSet + Convert.ToInt32(Math.Truncate(stateElement.OffSet.X));
                    f.yOffSet = f.yOffSet + Convert.ToInt32(Math.Truncate(stateElement.OffSet.Y));
                }
            }

            //Check if reverse movement and reverse order and sign x,y
            if (stateElement.Reverse == Enumeration.SequenceReverse.Reverse)
            {
                List <Frame> newListFrame   = new List <Frame>();
                List <Frame> newListCommand = new List <Frame>();

                foreach (Frame f in sequence.frames)
                {
                    if (f.type == Enumeration.TypeFrame.COMMAND)
                    {
                        newListCommand.Add(f);
                    }
                    else
                    {
                        f.xOffSet = -1 * f.xOffSet;
                        f.yOffSet = -1 * f.yOffSet;
                        newListFrame.Add(f);
                    }
                }
                newListFrame.Reverse();
                //add command
                foreach (Frame f in newListCommand)
                {
                    newListFrame.Add(f);
                }

                sequence.frames = newListFrame;
            }


            if (stateElement.Reverse == Enumeration.SequenceReverse.FixFrame)
            {
                this.m_frameIndex = this.FrameSpriteCount() - this.m_frameIndex;
            }
            else
            {
                this.m_frameIndex = 0;
            }

            this.firstTime = true;
        }