Impact

This forum is read only and just serves as an archive. If you have any questions, please post them on github.com/phoboslab/impact

9 years ago by FreddiePotato

I was wondering if it were possible to check for a collision at a given point. For example, specify a position and check to see if that position overlaps with an entity. Something like:
if (collisionPoint(this.pos.x+16, this.pos.y-16)){
     //do a thing
}

Any help would be appreciated. Thank you.

8 years ago by Joncom

You could add a function to entities that lets you check that:

ig.Entity.inject({
    isTouchingPosition: function(x, y) {
        return (
            x >= this.pos.x &&
            x < this.pos.x + this.size.x &&
            y >= this.pos.y &&
            y < this.pos.y + this.size.y
        );
    },
});

Then you could go:

var x = 10;
var y = 20;
if(player.isTouchingPosition(x, y)) {
    console.log('player is touching x/y:', x, y);
}
Page 1 of 1
« first « previous next › last »