I'm creating a shooter, it's still very early, but i'm implementing some polygon hitboxes.

So far i have created a polygon class, and i'm looking into how i can hook it onto my player.

I'm trying to stay away from having a Tick() function in my polygon class, and I would rather not update the position every tick (it would clutter up my tick functions). At the same time I would really like to have the positions in there somehow (it has a drawing function, and i will be using it for hit detection)

How would i go about implementing this polygon object into my entities?


This seems like a good place to use Composition.

Give the Entity your Polygon class as a property and update it whenever the entity moves.

public class Entity {
    public Polygon Hitbox { get; private set; }

    public void Move() {
        // stuff to move player
        this.Hitbox.X = this.Position.X;
        this.Hitbox.Width = ...
  • \$\begingroup\$ ofcourse! i just need to add a move method to my player! that would solve my problem of it cluttering my tick method, thanks! \$\endgroup\$ Oct 23 '12 at 22:03

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.