Using Artemis, Visual Studio, C# and Monogame.
Just starting to get a grasp on Artemis, but looking fo the proper place to add a clickable rectangle/area to an entity, there will be multiple entities on the screen.
Basic simple idea, i have small square sprites randomly showing and moving in the 2D play area. I need to be able to click on them and keeping it simple, delete the square.
In Artemis you have Components, Entities, Systems.
I know i'll be adding this rectangle area to the Texture2D square, guessing it should be its own component.
Trying to figure out
- Get the rectangle the size of the square, and stay with the square when it moves.
- How in some system, detect that this square was clicked or touched.
UPDATE
In my DrawableGameComponent entity. DrawPosition is a vector2 and set in the Main Game routine. It is the location of my square. I use that and texture size to calculate the size and location of my rectangle.
AreItemsIntersecting function will take the Mouse position when the screen is clicked, then i used that to create a little rect, and then checked if the 2 intersect. If they do, then the object was clicked.
public override void Update(GameTime gameTime)
{
    var bx = DrawPosition.X;
    var by = DrawPosition.Y;
    var w = _texture.Bounds.Width;
    var h = _texture.Bounds.Height;
    _bounds = new Rectangle((int)bx, (int)by, w+1, h+1);
    base.Update(gameTime);
}
public override void Draw(GameTime gameTime)
{
    if (_texture != null)
    {
        _spriteBatch.Begin();
        _spriteBatch.Draw(_texture, DrawPosition, Color.White);
        _spriteBatch.Draw(_texture, _bounds, Color.Transparent); 
        _spriteBatch.End();
    base.Draw(gameTime);
}
    public bool AreItemsIntersecting(int x, int y)
    {
        var vect = new Rectangle(x, y, 1, 1);
        if (vect.Intersects(_bounds))
        {
            return true;
        }
        return false;
    }
 
                        
I would create a
BoundingBoxcomponent. It will expose aBoundsproperty of typeRectangle.With this component in place you can create a
KillEntityOnClickSystemto handle the removal of clicked entities. You'll just need to check whether the mouse is inside theBoundsof the entityBoundingBoxwhen the mouse button is clicked.Hope this helps!