Exemple #1
0
        //=========================================================================================
        /// <summary>
        /// Sets the current animation sequence in use by this part.
        /// </summary>
        /// <param name="name"> Name of the sequence to use. </param>
        //=========================================================================================
        public void SetSequence( string name )
        {
            // Do nothing if no name given:

            if ( name == null || name.Length == 0 ) return;

            // Start from the first frame

            Restart();

            // Make a lowercase copy of the sequence name for case insensitive searchng:

            name = name.ToLower();

            // Only switch if the part exists:

            if ( m_sequences.ContainsKey(name) )
            {
                AnimationSequence new_sequence = m_sequences[name];

                if ( new_sequence != null )
                {
                    m_current_sequence = m_sequences[name];
                }
            }
        }
Exemple #2
0
        //=========================================================================================
        /// <summary>
        /// Constructor. Creates the animation part from the data in the given xml node.
        /// This node should contain data about the part such as sequences and underlying frames, 
        /// as well as the size and offset of the part.
        /// </summary>
        /// <param name="xml_node"> 
        /// XML Node containing all the sequences for the animation part.
        /// </param>
        //=========================================================================================
        public AnimationPart( XmlNode xml_node )
        {
            // On windows debug throw an exception if the node given is invalid:

            #if WINDOWS_DEBUG

                if ( xml_node == null ) throw new ArgumentNullException("Xml Node for animation part cannot be null");

            #endif

            // Initialise size to it's default:

            m_size = new Vector2( 128 , 128 );

            // Read the animation part data from the xml node

            if ( xml_node != null ) ReadXML( xml_node );

            // Run through the nodes attributes:

            foreach ( XmlAttribute attrib in xml_node.Attributes )
            {
                // See if it matches one of the attributes for an animation part:

                if ( attrib.Name.Equals( "OffsetX" , StringComparison.CurrentCultureIgnoreCase ) )
                {
                    try { m_offset.X = Convert.ToSingle( attrib.Value, Locale.DevelopmentCulture.NumberFormat ); } catch {}
                }
                else if ( attrib.Name.Equals( "OffsetY" , StringComparison.CurrentCultureIgnoreCase ) )
                {
                    try { m_offset.Y = Convert.ToSingle( attrib.Value, Locale.DevelopmentCulture.NumberFormat ); } catch {}
                }
                else if ( attrib.Name.Equals( "SizeX" , StringComparison.CurrentCultureIgnoreCase ) )
                {
                    try { m_size.X = Convert.ToSingle( attrib.Value ); } catch {}
                }
                else if ( attrib.Name.Equals( "SizeY" , StringComparison.CurrentCultureIgnoreCase ) )
                {
                    try { m_size.Y = Convert.ToSingle( attrib.Value, Locale.DevelopmentCulture.NumberFormat ); } catch {}
                }
            }

            // Get the first animation sequence and set it as the current sequence:

            {
                // Get enumerator into dictionary:

                Dictionary<string, AnimationSequence>.Enumerator e = m_sequences.GetEnumerator();

                // Get first part if it exists and make it the current sequence:

                if ( e.MoveNext() ) m_current_sequence = m_sequences[e.Current.Key];
            }
        }
Exemple #3
0
        //=========================================================================================
        /// <summary>
        /// Copy constructor. Creates this animation part from another one.
        /// </summary>
        /// <param name="part"> 
        /// Other animation part to make this one from.
        /// </param>
        //=========================================================================================
        public AnimationPart( AnimationPart part )
        {
            // Make sure it isn't null:

            if ( part != null )
            {
                // Copy all non-sequence data

                m_current_sequence      = part.CurrentSequence;
                m_current_frame_num     = part.m_current_frame_num;
                m_frame_time_elapsed    = part.m_frame_time_elapsed;
                m_offset                = part.m_offset;
                m_size                  = part.m_size;
                m_name                  = part.m_name;

                // See if the part has sequences:

                if ( part.m_sequences != null )
                {
                    // Run through all the sequences in the other part and copy:

                    Dictionary<string,AnimationSequence>.Enumerator e = part.m_sequences.GetEnumerator();

                    // Run through all sequences:

                    while ( e.MoveNext() )
                    {
                        // Copy this sequence: we only need a reference so that's ok..

                        m_sequences[e.Current.Key] = e.Current.Value;
                    }
                }
            }
        }