Example #1
0
        protected override bool VInheritedInit(XmlElement componentData)
        {
            Cv_Debug.Assert(componentData != null, "Must have valid component data.");

            var textureNode = componentData.SelectNodes("Texture").Item(0);

            if (textureNode != null)
            {
                Texture = textureNode.Attributes["resource"].Value;
            }

            var animationNode = componentData.SelectNodes("Animation").Item(0);

            if (animationNode != null)
            {
                if (animationNode.Attributes["fx"] != null)
                {
                    FrameX = int.Parse(animationNode.Attributes["fx"].Value);
                }

                if (animationNode.Attributes["fy"] != null)
                {
                    FrameY = int.Parse(animationNode.Attributes["fy"].Value);
                }

                if (animationNode.Attributes["loop"] != null)
                {
                    Looping = bool.Parse(animationNode.Attributes["loop"].Value);
                }

                if (animationNode.Attributes["speed"] != null)
                {
                    Speed = int.Parse(animationNode.Attributes["speed"].Value);
                }

                if (animationNode.Attributes["startFrame"] != null)
                {
                    StartFrame = int.Parse(animationNode.Attributes["startFrame"].Value);
                }

                if (animationNode.Attributes["endFrame"] != null)
                {
                    EndFrame = int.Parse(animationNode.Attributes["endFrame"].Value);
                }

                var subAnimations = animationNode.SelectNodes("SubAnimation");
                m_SubAnimations.Clear();
                m_CurrAnim = null;

                foreach (XmlElement subAnimation in subAnimations)
                {
                    var anim = new Cv_SpriteSubAnimation();

                    anim.ID         = subAnimation.Attributes["id"].Value;
                    anim.Speed      = int.Parse(subAnimation.Attributes["speed"].Value);
                    anim.StartFrame = int.Parse(subAnimation.Attributes["startFrame"].Value);
                    anim.EndFrame   = int.Parse(subAnimation.Attributes["endFrame"].Value);

                    AddAnimation(anim);
                }

                if (m_SubAnimations.Count > 0 && animationNode.Attributes["defaultAnim"] != null)
                {
                    var defaultAnim = animationNode.Attributes["defaultAnim"].Value;
                    m_sDefaultAnim = defaultAnim;
                    SetAnimation(defaultAnim);
                    CurrentFrame = m_CurrAnim != null ? m_CurrAnim.Value.StartFrame : 0;
                }

                if (StartFrame != null)
                {
                    CurrentFrame = StartFrame.Value;
                }
            }

            var mirroredNode = componentData.SelectNodes("Mirrored").Item(0);

            if (mirroredNode != null)
            {
                Mirrored = bool.Parse(mirroredNode.Attributes["status"].Value);
            }

            var scriptNode = componentData.SelectNodes("OnEndScript").Item(0);

            if (scriptNode != null)
            {
                OnEndScript = scriptNode.Attributes["resource"].Value;
            }

            return(true);
        }
Example #2
0
 public void AddAnimation(Cv_SpriteSubAnimation animation)
 {
     m_SubAnimations.Add(animation.ID, animation);
 }