The way I want to structure the engine is to load everything related to some entity inside of it.
public class Player : Entity
{
string AssetName;
public Player(string aname, Vector2 _position){
Position = _position;
AssetName = aname;
}
public void LoadContent(ContentManager contentManager){
Texture = contentManager.Load<Texture2D>(AssetName);
}
public override void Update(GameTime gameTime)
{
}
public override void Draw(SpriteBatch spriteBatch)
{
spriteBatch.Draw(Texture, Position, Color.White);
}
}
The Player class is inheriting from my abstract Entity class, which lots of game objects will inherit, such as enemies, chests, trees and so on…
This is the Entity class:
{
public abstract class Entity
{
protected Texture2D Texture{get; set;}
public Vector2 Position{get;set;}
public bool isSolid {get;set;}
public abstract void Update(GameTime gameTime);
public abstract void Draw(SpriteBatch spriteBatch);
}
}
On the Game1 class, I create a new Player by doing
private Player p;
and inside de Game1’s LoadContent function I wrote
p = new Player("PlayerSpriteSheet", new Vector2(30,30));
p.LoadContent(Content);
base.Initialize();
and inside the Draw function:
protected override void Draw(GameTime gameTime)
{
GraphicsDevice.Clear(Color.CornflowerBlue);
_spriteBatch.Begin();
p.Draw(_spriteBatch);
_spriteBatch.End();
base.Draw(gameTime);
}
Then I type at the terminal dotnet build
which returns no errors.
But when I try to dotnet run
, the Game window just don’t open at all, The terminal cursor stops blinking for a while, and then it returns to blink, like when it is when is idle.
The terminal cursor stops blinking for a while, and then it returns to blink, like when it is when is idle and the window just don’t start, like I never tried to run it.
Any idea on how can I fix that, or some wiser way to make it like I’m trying to do.