private Vector4 GetTileBounds(NewInstanceData Instance) { if (Instance.AtlasCache != null) { return(Instance.AtlasCache.MapRectangleToUVBounds(Instance.SpriteBounds)); } Gui.TileSheet sheet = null; Texture2D tex = null; bool exists = false; if (Instance.TextureAsset == null) { Instance.TextureAsset = "newgui/error"; } exists = Atlas.TryGetValue(Instance.TextureAsset, out sheet); if (!exists) { tex = AssetManager.GetContentTexture(Instance.TextureAsset); if (tex == null) { return(Vector4.Zero); // Actually should never happen. } sheet = new Gui.TileSheet(tex.Width, tex.Height, new Rectangle(0, 0, tex.Width, tex.Height), tex.Width, tex.Height, false); Atlas.Add(Instance.TextureAsset, sheet); RebuildAtlas(); NeedsRendered = true; } Instance.AtlasCache = sheet; return(sheet.MapRectangleToUVBounds(Instance.SpriteBounds)); }
public static int ConvertRectToIndex(this Gui.TileSheet Sheet, Rectangle Rect) { var x = Rect.X / Sheet.TileWidth; var y = Rect.Y / Sheet.TileHeight; return((Sheet.Columns * y) + x); }
private static void InitializeVoxels() { if (VoxelsInitialized) { return; } VoxelsInitialized = true; var cubeTexture = AssetManager.GetContentTexture(ContentPaths.Terrain.terrain_tiles); VoxelTypeList = FileUtils.LoadJsonListFromDirectory <VoxelType>(ContentPaths.voxel_types, null, v => v.Name); var terrainTiles = new Gui.TileSheet(cubeTexture.Width, cubeTexture.Height, cubeTexture.Bounds, 32, 32, false); short id = 2; foreach (VoxelType type in VoxelTypeList) { VoxelTypes[type.Name] = type; VoxelPrimitives[type.Name] = CreateVoxelPrimitive(cubeTexture, 32, 32, type.Top, type.Bottom, type.Sides); if (type.Name == "_empty") { _EmptyVoxelType = type; type.ID = 0; } else if (type.Name == "_designation") { _DesignationVoxelType = type; type.ID = 1; } else { type.ID = id; id += 1; } if (type.HasTransitionTextures) { type.TransitionTextures = CreateTransitionUVs(cubeTexture, 32, 32, type.TransitionTiles, type.Transitions); } type.ExplosionSound = SoundSource.Create(type.ExplosionSoundResource); type.HitSound = SoundSource.Create(type.HitSoundResources); } VoxelTypeList = VoxelTypeList.OrderBy(v => v.ID).ToList(); if (VoxelTypeList.Count > VoxelConstants.MaximumVoxelTypes) { throw new InvalidProgramException(String.Format("There can be only {0} voxel types.", VoxelConstants.MaximumVoxelTypes)); } Console.WriteLine("Loaded Voxel Library."); }
public VariableWidthFont(Texture2D Texture, int TextureWidth, int TextureHeight, Rectangle Source) { var Data = new Texture(Texture); Sheet = new TileSheet(TextureWidth, TextureHeight, Source, 1, 1, false); Glyphs = new List <Rectangle>(); var x = 0; var y = 0; bool allZeros = true; while (y < Data.Height) { int glyphHeight = 1; while (x < Data.Width) { var pix = Data.GetPixel(x, y); if (pix != new Color(0, 0, 0, 0)) { allZeros = false; } if (pix == new Color(255, 0, 255, 255)) { x += 1; } else { var glyph = ExtractRect(Data, x, y); Glyphs.Add(glyph); x += glyph.Width; glyphHeight = glyph.Height; } } x = 0; y += glyphHeight; } if (allZeros) { Console.Out.WriteLine("Failed to load font {0} something wrong?", Texture.Name); } }
public void ResetAtlasBounds(Rectangle MyBounds, Rectangle AtlasBounds) { Sheet = new TileSheet(AtlasBounds.Width, AtlasBounds.Height, MyBounds, 1, 1, false); }