/// <summary> /// Initializes a new instance of the <see cref="Game1"/> class. /// </summary> public Game1() : base(new Point(1024, 768), new Point(1024, 768)) { // Load UseVerticalSync = true; ShowMouseCursor = true; _skinManager = new SkinManager("Default"); _screenManager = new ScreenManager(this, _skinManager, "Font/Arial", 14); GrhInfo.Load(ContentPaths.Build, _screenManager.Content); var ts = new TestScreen(_screenManager); _screenManager.ActiveScreen = ts; Closed += Game1_Closed; KeyPressed += Game1_KeyPressed; // Shove GUI elements into a texture atlas so we can test them with atlasing var guiGrhs = GrhInfo.GrhDatas.SelectMany(x => x.Frames).Distinct() .Where(x => x.Categorization.Category.ToString().StartsWith("gui", StringComparison.OrdinalIgnoreCase)); _guiTextureAtlas = new TextureAtlas(guiGrhs); Run(); }
/// <summary> /// Constructs an atlas for the map using the given set of GrhIndexes. /// </summary> /// <param name="grhIndexes">The GrhIndexes.</param> void BuildAtlas(IEnumerable<GrhIndex> grhIndexes) { if (grhIndexes == null || grhIndexes.Count() == 0) { _mapAtlases = new List<Image>(0); return; } // First, grab the GrhData for each GrhIndex, making sure to skip null GrhDatas. Then, // grab all the frames and add them. Stationary GrhDatas will end up adding their self, while // animated ones will add all their frames, so this will end up adding them all no matter the type. // Finally, use Distinct to ensure we have no duplicates. var validGrhDatas = grhIndexes.Select(GrhInfo.GetData).Where(x => x != null); var atlasItems = validGrhDatas.SelectMany(x => x.Frames); atlasItems = atlasItems.Distinct(); // Dispose of the old atlas if needed if (_atlas != null && !_atlas.IsDisposed) _atlas.Dispose(); // Generate the atlas out of all the items _atlas = new TextureAtlas(atlasItems); }