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

1 decade ago by ansimuz

Its there a way to detect if an entity is surrounded by collision tiles, in other is stuck and i want to kill it if so.

Thanks :)

1 decade ago by dominic

You can use the Map's .getTile(x, y) method to check surrounding tiles. Depending on what you mean with "stuck", you may have to check the neighboring 4 tiles (or even 8 with the corners) or just the current tile.

Something like this (untested):
// in your entity's update():

// find this entity's center point
var tx = this.pos.x + this.size.x/2,
	ty = this.pos.y + this.size.y/2;

if( ig.game.collisionMap.getTile(tx, ty) ) {
	// current tile is solid
}

1 decade ago by ansimuz

Works like charm. Thanks a lot.
Page 1 of 1
« first « previous next › last »