Im semi new to monogame, but i know my logic is correct(code below) but when i move the mouse and click with it nothing happens. Please help!
class LevelTest : GameScreen
{
Game game;
InputManager input;
private Player _player;
private GameObject _num1;
private List<Component> _components;
MouseState _currentMouseState;
MouseState _previousMouseState;
public override void LoadContent(ContentManager Content, InputManager inputManager)
{
base.LoadContent(Content, inputManager);
game = new Game();
input = new InputManager(game);
_player = new Player(Content.Load<Texture2D>("PlaceHolderPlayer"));
_num1 = new GameObject(Content.Load<Texture2D>("PlaceHolderPlayer"));
_num1.X = 0;
_num1.Y = 0;
_components = new List<Component>()
{
_player
};
_currentMouseState = Mouse.GetState();
_previousMouseState = _currentMouseState;
}
public override void UnloadContent()
{
base.UnloadContent();
}
public override void Update(GameTime gameTime)
{
input.Update(gameTime);
_previousMouseState = _currentMouseState;
_currentMouseState = Mouse.GetState();
foreach (var component in _components)
component.Update(gameTime);
_player.X = _currentMouseState.X;
_player.Y = _currentMouseState.Y;
if (_previousMouseState.LeftButton == ButtonState.Released && _currentMouseState.LeftButton == ButtonState.Pressed)
{
Console.WriteLine("Left button pressed");
}
else if (_previousMouseState.RightButton == ButtonState.Released && _currentMouseState.RightButton == ButtonState.Pressed)
{
Console.WriteLine("Right button pressed");
}
else
Console.WriteLine("No button pressed");
}
public override void Draw(SpriteBatch spriteBatch)
{
GameTime gameTime = new GameTime();
base.Draw(spriteBatch);
foreach(var component in _components)
component.Draw(gameTime, spriteBatch);
}
}