public void DrawIso(SpriteBatch batch, Rectangle rectangle, Vector2 offset, Vector2 viewportPosition, float opacity, int tilewidth, int tileheight) { Vector2 destPos = new Vector2((int)this.X, (int)this.Y); destPos.X += (int)(rectangle.Width / 2); destPos.Y += (int)(rectangle.Height / 4); //stop gap to center viewport on screen. //for some reason the player is always off center //dividing the height and width seem to work with different screen sizes Vector2 viewoffset = new Vector2((rectangle.Height / 12), (rectangle.Width / 7)); destPos -= viewportPosition + viewoffset; destPos = Isometric.TwoDToIso(new Vector2((int)destPos.X, (int)destPos.Y)); if (destPos.X > 0 && destPos.X < (rectangle.Width - tilewidth) && destPos.Y > 0 && destPos.Y < (rectangle.Height - tileheight)) { batch.Draw(_Texture, new Rectangle((int)destPos.X, (int)destPos.Y, this.Width, this.Height), new Rectangle(0, 0, _Texture.Width, _Texture.Height), Color.White * opacity); } }
public void DrawIso(IBatchedDrawingService d, IList <Tileset> tilesets, Rectangle rectangle, Vector2 viewportPosition, int tileWidth, int tileHeight) { int i = 0; Vector2 destPos = new Vector2(0, 0); Vector2 centTile = new Vector2((int)viewportPosition.X / tileHeight, (int)viewportPosition.Y / tileHeight); Console.WriteLine(centTile + " " + viewportPosition); TileInfo info = new TileInfo(); if (_TileInfoCache == null) { BuildTileInfoCache(tilesets); } foreach (Tileset tileset in tilesets) { if (tileset.tiles == null) { Texture2D[] tiles = new Texture2D[_TileInfoCache.Length]; for (int k = 0; k < _TileInfoCache.Length; k++) { Texture2D test = new Texture2D(d.GraphicsDevice, tileWidth, tileHeight); test = GetTileTexture(k + 1, tileset, test); tiles[k] = test; } tileset.tiles = tiles; Console.WriteLine("tiles added"); } } for (int y = (int)centTile.Y - (Height / 2); y <= (int)centTile.Y + (Height / 2); y++) { for (int x = (int)centTile.X - (Width / 2); x <= (int)centTile.X + (Width / 2); x++) { destPos.X = (x - centTile.X) * tileHeight; destPos.Y = (y - centTile.Y) * tileHeight; destPos = Isometric.TwoDToIso(destPos); destPos.X += (rectangle.Width) / 2; destPos.Y += (rectangle.Height) / 2; if (destPos.X > (0 - tileWidth) && destPos.X < (rectangle.Width + tileWidth) && destPos.Y > (0 - tileWidth) && destPos.Y < (rectangle.Height + tileHeight)) { Vector2 testtile = new Vector2(x, y); if (testtile.X >= 0 && testtile.X < Width && testtile.Y >= 0 && testtile.Y < Height) { i = ((int)testtile.Y * Width) + (int)testtile.X; int index = Tiles[i] - 1; if ((index >= 0) && (index < _TileInfoCache.Length)) { d.Draw(new UITexture(tilesets[0].tiles[index]), destPos, null, Color.White * this.Opacity, 0f, new Vector2(tileWidth / 2f, tileHeight / 2f), 1f, 0f, 0); } } } } } }
public void DrawIso(SpriteBatch batch, IList <Tileset> tilesets, Rectangle rectangle, Vector2 viewportPosition, int tileWidth, int tileHeight) { TileInfo info = new TileInfo(); if (_TileInfoCache == null) { BuildTileInfoCache(tilesets); } for (int y = 0; y < this.Height; y++) { for (int x = 0; x < this.Width; x++) { Vector2 destPos = new Vector2((int)x * (tileWidth / 2), (int)y * (tileHeight)); destPos.X += (int)((rectangle.Width) / 2); destPos.Y += (int)((rectangle.Height) / 4); //stop gap to center viewport on screen. //for some reason the player is always off center //dividing the height and width seem to work with different screen sizes Vector2 viewoffset = new Vector2((rectangle.Height / 12), (rectangle.Width / 7)); destPos -= viewportPosition + viewoffset; destPos = Isometric.TwoDToIso(new Vector2((int)destPos.X, (int)destPos.Y)); if (destPos.X > (0 - (tileWidth * 2)) && destPos.X < (rectangle.Width + (tileWidth * 2)) && destPos.Y > (0 - (tileHeight * 2)) && destPos.Y < (rectangle.Height + (tileHeight * 2))) { int i = ((int)y * Width) + (int)x; byte flipAndRotate = FlipAndRotate[i]; SpriteEffects flipEffect = SpriteEffects.None; float rotation = 0f; if ((flipAndRotate & Layer.HorizontalFlipDrawFlag) != 0) { flipEffect |= SpriteEffects.FlipHorizontally; } if ((flipAndRotate & Layer.VerticalFlipDrawFlag) != 0) { flipEffect |= SpriteEffects.FlipVertically; } if ((flipAndRotate & Layer.DiagonallyFlipDrawFlag) != 0) { if ((flipAndRotate & Layer.HorizontalFlipDrawFlag) != 0 && (flipAndRotate & Layer.VerticalFlipDrawFlag) != 0) { rotation = (float)(Math.PI / 2); flipEffect ^= SpriteEffects.FlipVertically; } else if ((flipAndRotate & Layer.HorizontalFlipDrawFlag) != 0) { rotation = (float)-(Math.PI / 2); flipEffect ^= SpriteEffects.FlipVertically; } else if ((flipAndRotate & Layer.VerticalFlipDrawFlag) != 0) { rotation = (float)(Math.PI / 2); flipEffect ^= SpriteEffects.FlipHorizontally; } else { rotation = -(float)(Math.PI / 2); flipEffect ^= SpriteEffects.FlipHorizontally; } } int index = Tiles[i] - 1; if ((index >= 0)) { info = _TileInfoCache[index]; batch.Draw(info.Texture, destPos, info.Rectangle, Color.White * this.Opacity, rotation, new Vector2(tileWidth / 2f, tileHeight / 2f), 1f, flipEffect, 0); } } } } }