public static void GetTilesetTileDimensions(int sheetNum, out int x, out int y) { if (tileData[sheetNum] == null) { tileData[sheetNum] = new TileMetadata(); tileData[sheetNum].Load(Paths.CachedGFXPath + "Tile\\Tiles" + sheetNum + ".tile"); } x = Graphics.TextureManager.tileData[sheetNum].Size.Width / Graphics.TextureManager.TILE_SIZE; y = Graphics.TextureManager.tileData[sheetNum].Size.Height / Graphics.TextureManager.TILE_SIZE; }
public static Texture GetTile(int sheetNum, Maps.Loc2D tileLoc) { try { if (tileData[sheetNum] == null) { tileData[sheetNum] = new TileMetadata(); tileData[sheetNum].Load(Paths.CachedGFXPath + "Tile\\Tiles" + sheetNum + ".tile"); } int tileNum = (tileData[sheetNum].Size.Width / TILE_SIZE) * tileLoc.Y + tileLoc.X; Texture cacheSheet = tileCache.Get(sheetNum + "-" + tileLoc.X + "-" + tileLoc.Y); if (cacheSheet != null) { return(cacheSheet); } if (sheetNum > -1 && sheetNum < TOTAL_TILE_SHEETS && tileNum > -1 && tileNum < tileData[sheetNum].TotalTiles) { Texture sheet = new Texture(); byte[] tileBytes = new byte[tileData[sheetNum].TileSizes[tileNum]]; using (FileStream stream = new FileStream(Paths.CachedGFXPath + "Tile\\Tiles" + sheetNum + ".tile", FileMode.Open, FileAccess.Read, FileShare.Read)) { // Seek to the location of the tile stream.Seek(tileData[sheetNum].GetTilePosition(tileNum), SeekOrigin.Begin); stream.Read(tileBytes, 0, tileBytes.Length); } using (MemoryStream tileStream = new MemoryStream(tileBytes)) { sheet.LoadPixelsFromBytes(tileStream); sheet.LoadTextureFromPixels32(); } tileCache.Add(sheetNum + "-" + tileLoc.X + "-" + tileLoc.Y, sheet); return(sheet); } } catch (Exception ex) { Logs.Logger.LogError(new Exception("Error retrieving tile " + tileLoc.X + ", " + tileLoc.Y + " from Tileset #" + sheetNum + "\n", ex)); } tileCache.Add(sheetNum + "-" + tileLoc.X + "-" + tileLoc.Y, ErrorTexture); return(ErrorTexture); }