I'm trying out Monogame because my course has a simple game programming class in it which is just going over basics. The final project will be using Monogame so I've been getting ahead and making my game.
Anyway, each player (Tank) has a list of Shells (bullets) and a list of Tracks (tank tracks). I load their content in the player's LoadContent
method. LoadContent
is called when the game is ran.
Let's say I wanted to add a new player sometime later in the game for whatever odd reason. I would do something along the lines of:
entityManager.Add(new Player("Player Name", resourceManager.GetTexture("BlueTank"))
{
set initial position and keybinds here,
};
This successfully creates a new player and loads its texture but what about its bullets textures, sound effects, track textures etc... Since LoadContent
only gets called once at the start the code below will not run.
Example of the player's LoadContent
method:
// Match the players bullets with the players colour
switch (Texture.Tag)
{
case "BlueTank":
shellTexture = resourceManager.GetTexture("BlueShell");
break;
case "DarkTank":
shellTexture = resourceManager.GetTexture("DarkShell");
break;
}
// After this I use the resourceManager to set private Texture2D's and sound effects for the bullets, tracks and player.
// e.g.
trackTexture = resourceManager.GetTexture("Track");
When I finally shoot a bullet I set the bullets texture and sound effect properties to the private ones in the player.
When a player dies I currently just set their IsActive
bool to false and the entity manager will remove them completely so I'm stuck on how to load content again.
I feel like I'm overthinking this but I can't seem to find a clean and simple way to get this done. Also I'm bad at explaining things hopefully this isn't too much of a mess.
Edit: Would it be a bad idea to pass the resource manager in the players constructor and just create a method for loading that is called in the players constructor? That way when a player is created the content is loaded for that player. It's only a small game for a basic school project. I could potentially do all the content setting outside of the player itself and in the GameplayState by looping through unloaded entities or something.