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 | In development |
Author | Apocalypse Theory |
Tags | 2D, Short, Singleplayer |
More posts
- What a Weekend54 days ago
- Learning Day 659 days ago
- Learning Day 560 days ago
- Learning Day 461 days ago
- Learning Day 362 days ago
- Learning Day 263 days ago
- Getting Started64 days ago
Leave a comment
Log in with itch.io to leave a comment.