using System; using System.Collections.Generic; using System.Text; using Microsoft.Xna.Framework; using Microsoft.Xna.Framework.Content; using Microsoft.Xna.Framework.Graphics; namespace Tiles { class Tile { private Texture2D texture; private Vector2 position; private Vector2 nextDrawPosition; private Color color; private float layer; private int tilesX; private int tilesY; private List textureBasket; private GraphicsDeviceManager graphics; #region Properties public Texture2D Texture { get { return texture; } set { texture = value; } } public Vector2 Position { get { return position; } set { position = value; } } public Color Color { get { return color; } set { color = value; } } public float Layer { get { return layer; } set { layer = value; } } public List TextureBasket { get { return textureBasket; } set { textureBasket = value; } } #endregion public void Initialize() { CalculateNumberTiles(graphics.PreferredBackBufferWidth, graphics.PreferredBackBufferHeight); while (CalculateNumberTiles().X >= TextureBasket.Count()) { TextureBasket.Add(texture); } while (CalculateNumberTiles().Y >= TextureBasket.Count()) { textureBasket.Add(texture); } } private Vector2 CalculateNumberTiles(int screenX, int screenY) { tilesX = (screenX / texture.Width) + 2; tilesY = (screenY / texture.Height) + 2; return new Vector2(tilesX, tilesY); } #region Comment /// /// Draws the currentTile to the screen /// /// #endregion public void Draw(SpriteBatch spriteBatch) { #region Old /* Rectangle sourceRectangle = new Rectangle(0, 0, texture.Width, texture.Height); spriteBatch.Draw(texture, nextDrawPosition, sourceRectangle, color, 0.0f, new Vector2(0, 0), 1.0f, SpriteEffects.None, layer); position.X += texture.Width; nextDrawPosition.Y += texture.Height; if (nextDrawPosition.Y >= texture.Height * tilesY) { nextDrawPosition.X += texture.Width; nextDrawPosition.Y = 0; } */ #endregion foreach (Texture2D texture in textureBasket) { Rectangle sourceRectangle = new Rectangle(0, 0, texture.Width, texture.Height); spriteBatch.Draw(texture, nextDrawPosition, sourceRectangle, color, 0.0f, new Vector2(0, 0), 1.0f, SpriteEffects.None, layer); } } } }