Don't like ads? PRO users don't see any ads ;-)

SmlEngine.Sprites.Base.WorldMap.WorldAnimatedTile (0.04aB13)

By: smc_gamer on Aug 5th, 2012  |  syntax: C#  |  size: 2.60 KB  |  hits: 19  |  expires: Never
download  |  raw  |  embed  |  report abuse  |  print
Text below is selected. Please press Ctrl+C to copy to your clipboard. (⌘+C on Mac)
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Text;
  5.  
  6. using Microsoft.Xna.Framework;
  7. using Microsoft.Xna.Framework.Content;
  8. using Microsoft.Xna.Framework.Graphics;
  9.  
  10. using SmlEngine.Graphics;
  11. using SmlEngine.Extensions;
  12.  
  13.  
  14. namespace SmlEngine.Sprites.Base.WorldMap
  15. {
  16.     /// <summary>
  17.     /// An animated tile for the world map.
  18.     /// </summary>
  19.     public class WorldAnimatedTile : ICloneable, IWorldDrawable
  20.     {
  21.         // To prevent confusion:
  22.         // Animated frame refers to one frame of an animated world tile.
  23.         // Rendered frame refers to one frame drawn to the screen.
  24.  
  25.         #region Fields and Properties
  26.         public int id;
  27.  
  28.         public WorldTile worldTile { get; private set; }
  29.         public Vector2 Position { get; private set; }
  30.  
  31.         public Vector2 Size
  32.         {
  33.             get
  34.             {
  35.                 return worldTile.Size;
  36.             }
  37.         }
  38.  
  39.         private bool isDataSet = false;
  40.         #endregion
  41.  
  42.         #region Constructors
  43.         public WorldAnimatedTile(int c_id, string c_contentPath, List<Rectangle> c_sourceRect, ContentManager cm, int frameTime)
  44.         {
  45.             worldTile = new WorldTile(c_contentPath, c_sourceRect);
  46.             worldTile.SetData(frameTime);
  47.  
  48.             LoadContent(null, cm);
  49.         }
  50.  
  51.         public WorldAnimatedTile(GraphicsDevice gd, string c_FilePath, List<Rectangle> c_frameRects, ContentManager cm, int frameTime)
  52.         {
  53.             worldTile = new WorldTile(c_FilePath, c_frameRects);
  54.             worldTile.SetData(frameTime);
  55.             LoadContent(gd, cm);
  56.         }
  57.  
  58.         public WorldAnimatedTile() { }
  59.         #endregion
  60.  
  61.         #region Methods
  62.         public void Draw(GameTime gameTime, SpriteBatch sb)
  63.         {
  64.             worldTile.Draw(gameTime, sb, Position);
  65.         }
  66.  
  67.         public void Update(GameTime gameTime) { }
  68.         public Object Clone()
  69.         {
  70.             WorldAnimatedTile a = new WorldAnimatedTile();
  71.             a.worldTile = worldTile.Clone();
  72.             a.id = id;
  73.             a.Position = Position;
  74.             return a;
  75.         }
  76.  
  77.         public void LoadContent(GraphicsDevice gd, ContentManager cm)
  78.         {
  79.             worldTile.LoadContent(gd, cm, true);
  80.         }
  81.  
  82.         public void UnloadContent()
  83.         {
  84.             worldTile.UnloadContent();
  85.         }
  86.  
  87.         public void SetData(Vector2 position)
  88.         {
  89.             if (!isDataSet)
  90.             {
  91.                 Position = position;
  92.                 isDataSet = true;
  93.             }
  94.         }
  95.         #endregion
  96.     }
  97. }