Example #1
0
        /// <summary>
        /// Add an AnimationLayer
        /// </summary>
        /// <returns>Created layer</returns>
        public SceneLayer CreateLayer()
        {
            SceneLayer layer = new SceneLayer(this);

            Layers.Add(layer);
            Layers.Sort();

            return(layer);
        }
Example #2
0
        /// <summary>
        /// Constructor
        /// </summary>
        /// <param name="layer">Layer to get the frame from</param>
        /// <param name="time">Time of the frame</param>
        /// <exception>ArgumentNullExecption</exception>
        public SceneFrame(SceneLayer layer, TimeSpan time)
        {
            if (layer == null)
            {
                throw new ArgumentNullException("layer");
            }

            Layer = layer;

            KeyFrame next = layer.GetNextKeyFrame(time);
            KeyFrame prev = layer.GetPreviousKeyFrame(time);

            if (next == null | prev == null)
            {
                TileID = -1;
                TextID = -1;
                return;
            }


            // Length between two keyframes
            float delta;

            if (next.Time - prev.Time == TimeSpan.Zero)
            {
                delta = 1.0f;
            }
            else
            {
                delta = (float)(time - prev.Time).TotalMilliseconds / (float)(next.Time - prev.Time).TotalMilliseconds;
            }


            Time = time;

            // Tile
            TileID  = prev.TileID;
            BgColor = prev.BgColor;
            Point loc = prev.TileLocation;

            loc.Offset(
                (int)((next.TileLocation.X - prev.TileLocation.X) * delta),
                (int)((next.TileLocation.Y - prev.TileLocation.Y) * delta));
            TileLocation = loc;

            // Text
            TextID = prev.TextID;
            Rectangle rect = prev.TextRectangle;

            rect.Offset(
                (int)((next.TextRectangle.X - prev.TextRectangle.X) * delta),
                (int)((next.TextRectangle.Y - prev.TextRectangle.Y) * delta));
            TextRectangle = rect;
        }
Example #3
0
 /// <summary>
 /// Removes an AnimationLayer
 /// </summary>
 /// <param name="layer">Layer</param>
 public void RemoveLayer(SceneLayer layer)
 {
     Layers.Remove(layer);
 }
Example #4
0
        /// <summary>
        /// Loads the animation from a xml file
        /// </summary>
        /// <param name="xml">XmlNode to load</param>
        /// <returns></returns>
        public bool Load(XmlNode xml)
        {
            if (xml == null)
            {
                return(false);
            }

            if (xml.Name != XmlTag)
            {
                Trace.WriteLine("Expecting \"" + XmlTag + "\" in node header, found \"" + xml.Name + "\" when loading Scene.");
                return(false);
            }

            Name = xml.Attributes["name"].Value;

            // Process datas
            XmlNodeList nodes = xml.ChildNodes;

            foreach (XmlNode node in nodes)
            {
                switch (node.Name.ToLower())
                {
                case "tileset":
                {
                    TileSetName = node.Attributes["name"].Value;
                    TileSet     = ResourceManager.CreateAsset <TileSet>(TileSetName);
                    if (TileSet == null)
                    {
                        break;
                    }

                    Vector2 size = new Vector2(1.0f, 1.0f);
                    if (node.Attributes["scalew"].Value != null)
                    {
                        size.X = float.Parse(node.Attributes["scalew"].Value);
                    }
                    if (node.Attributes["scaleh"].Value != null)
                    {
                        size.Y = float.Parse(node.Attributes["scaleh"].Value);
                    }

                    TileSet.Scale = size;
                }
                break;


                case "layer":
                {
                    SceneLayer layer = CreateLayer();
                    layer.Load(node);
                }
                break;


                case "stringtable":
                {
                    StringTableName = node.Attributes["name"].Value;
                    StringTable     = ResourceManager.CreateAsset <StringTable>(StringTableName);
                }
                break;

                case "font":
                {
                    FontName = node.Attributes["name"].Value;
                    Font     = ResourceManager.CreateAsset <BitmapFont>(FontName);
                }
                break;

                default:
                {
                    Trace.WriteLine("Animation : Unknown node element found (" + node.Name + ")");
                }
                break;
                }
            }

            return(true);
        }