Ejemplo n.º 1
0
        public void Draw(SpriteBatch spriteBatch, Camera camera)
        {
            Vector2 screenPosition = Vector2.Zero;
            int firstTileX = 0;
            int firstTileY = 0;
            int offsetX = 0;
            int offsetY = 0;
            int tilesToDrawAcross = 0;
            int tilesToDrawDown = 0;

            if (spriteBatch != null && camera != null)
            {
                firstTileX = (int)camera.Location.X / (int)tileSize.X;
                firstTileY = (int)camera.Location.Y / (int)tileSize.Y;
                offsetX = (int)camera.Location.X % (int)tileSize.X;
                offsetY = (int)camera.Location.Y % (int)tileSize.Y;
                tilesToDrawDown = (int)Math.Ceiling(camera.Size.Y / tileSize.Y) + 1;
                tilesToDrawAcross = (int)Math.Ceiling(camera.Size.X / tileSize.X) + 1;

                for (int i = 0; i < tilesToDrawDown && i < this.mapRows.Count; i++)
                {
                    for (int j = 0; j < tilesToDrawAcross && j < this.mapRows[i].Cells.Count; j++)
                    {
                        screenPosition.X = (j * tileSize.X) - offsetX;
                        screenPosition.Y = (i * tileSize.Y) - offsetY;
                        this.mapRows[i + firstTileY].Cells[j + firstTileX].Draw(spriteBatch, this.spriteSheet, screenPosition, tileSize);
                    }
                }
            }
        }
Ejemplo n.º 2
0
 public void Draw(SpriteBatch spriteBatch, Camera camera, int index)
 {
 }
Ejemplo n.º 3
0
        /// <summary>
        /// Initializes the control.
        /// </summary>
        protected override void Initialize()
        {
            Random rand = new Random();
            spriteBatch = new SpriteBatch(base.GraphicsDevice);
            selectedMapCells = new MapCells();

            camera = new Camera(Vector2.Zero, new Vector2(this.Width, this.Height), new Vector2(1f, 1f));

            this.MouseClick +=new MouseEventHandler(MapViewer_MouseClick);

            Application.Idle += delegate { Invalidate(); };
        }
Ejemplo n.º 4
0
        /// <summary>
        /// Initializes the control.
        /// </summary>
        protected override void Initialize()
        {
            Random rand = new Random();
            //int val = 0;
            spriteBatch = new SpriteBatch(base.GraphicsDevice);
            //for (int i = 0; i < 100; i++)
            //{
            //    map.MapRows.Add(new MapRow());
            //    for (int j = 0; j < 100; j++)
            //    {
            //        val = (rand.Next() % 3);
            //        map.MapRows[i].Cells.Add(new MapCell(new Tile("Grass", (byte)val, new Vector2(val * 48, 0))));
            //    }
            //}

            camera = new Camera(Vector2.Zero, new Vector2(this.Width, this.Height), new Vector2(.6f, .6f));
            //LoadContent();
            // Hook the idle event to constantly redraw our animation.
            Application.Idle += delegate { Invalidate(); };
        }