public override void Render(Graphics graphics, Camera camera) { for (var y = 1; y <= map.Height; y++) { for (var x = 1; x <= map.Width; x++) { var index = Indices[x - 1, y - 1]; //-1 because indices are zero indexed. var tileset = Tileset.TilesetForPosition(index, map.Tilesets); //Tileset the index belongs to. var subTexturePosition = index - tileset.FirstGid; //Resets position to start at 0 for the subtexture positioning. if (subTexturePosition <= -1) { continue; //Don't render empty tiles. } var worldpos = Isometric.IsometricToWorld(new Point(x - 1, y - 1), map); //Isometric Projection to world coords. //Culling if (worldpos.X > camera.Bounds.X + camera.Bounds.Width || //Right side worldpos.Y > camera.Bounds.Y + camera.Bounds.Height || //Bottom worldpos.X < camera.Bounds.X - map.LargestTileSize.X || //Left worldpos.Y < camera.Bounds.Y - map.LargestTileSize.Y) //Top { continue; //Don't draw l } var columnRounding = subTexturePosition % tileset.Columns; var sourceRect = new RectangleF //Subposition in texture. { X = (columnRounding * tileset.TileWidth), Y = (subTexturePosition / tileset.Columns) * tileset.TileHeight, //Y needs rounding. Width = tileset.TileWidth, Height = tileset.TileHeight }; //Finally draw. graphics.Batcher.Draw(tileset.Texture, worldpos, sourceRect, Color.White, 0, new Vector2(0, 0), 1, SpriteEffects.None, 0); } } }