Learning Day 7
Yesterday was a slow day for game development. I had a tricky problem at work that had been delaying my work I put some extra hours into solving.
Scene Cleanup
In our scenes we do not add in sprites directly, except for the LogoScene which we will clean up later. Instead we load components.
Looking over the API and Stackoverflow I believe that UnloadContent
is called whenever an object is disposed of, or is removed from the Game.Componenets
.
With this in mind and the fact I save all of our components to a dictionary already clean up was rather simple
protected override void UnloadContent() { foreach (var component in _components) { component.Value.Dispose(); } base.UnloadContent(); }
Component Cleanup
Using the same logic I set up a dictionary on components to store all loaded assets.
List<string> _assets = new List<string>();
Then I set up a LoadAssets
function to load my spritesheets.
private void LoadAssets(string asset) { _assets.Add(asset); SpriteAtlas.Instance.RegisterSpriteSheet(asset); }
When the component is disposed
of by the scene then the UnloadContent
should run
protected override void UnloadContent() { foreach (var asset in _assets) { SpriteAtlas.Instance.DeregisterSpriteSheet(asset); } base.UnloadContent(); Game.Components.Remove(this); }
That's all for now
Today I should be caught up at work so I should have a larger update for tomorrow and finally get the settings implemented.
Target Practice
A small 2d target practice game
Status | Prototype |
Author | Apocalypse Theory |
Tags | 2D, Short, Singleplayer |
More posts
- What a WeekendMar 25, 2024
- Learning Day 6Mar 20, 2024
- Learning Day 5Mar 19, 2024
- Learning Day 4Mar 18, 2024
- Learning Day 3Mar 17, 2024
- Learning Day 2Mar 16, 2024
- Getting StartedMar 15, 2024
Leave a comment
Log in with itch.io to leave a comment.