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 Kxen

Hi.

I'm making a game where the player can spawn entities with the mouse (I have a pointer entity that is following the mouse) and I want to make so that you can only spawn entities in certain tiles. So I need to check whether my pointer entity is overlapping one of these tiles or not.

My only idea is to use the collision map and handleMovementTrace() but I don't really know how and haven't got it to work so far.

Any suggestion or solution?

1 decade ago by fugufish

you can get some ideas from here

http://impactjs.com/forums/help/passing-through-entity-from-only-one-direction

1 decade ago by Kxen

Thanks fugufish. I actually tried that just now and it seems that it doesn't detect collision when it's not colliding "naturally" (the pointer is moving by updating pos.x/y manually and not via velocity, not sure why this would make a difference though but either I'm stupid or it really does...).

EDIT: Actually got it to work by setting the velocity to 1 on the pointer... so it seems my assumption above was correct. Thanks again, I will see what I can do next!

EDIT2: All good and working like I wanted it to. :) Still not sure this is the best solution since it's probably not meant to use the collision map like this (and also seeing I had to put in a totally unnecessary velocity) so if anyone has a better solution please let me know.

EDIT3: Forgot to add the solution:

In the pointer entity:
handleMovementTrace: function( res ) {

	if( res.tile.x == 1 || res.tile.y == 1 ) {
		if (ig.input.pressed('mouse')) {
			ig.game.spawnEntity( "EntityUnit", ig.game.screen.x + ig.input.mouse.x, ig.game.screen.y + ig.input.mouse.y);
		}
	}
}

1 decade ago by dominic

You can lookup the tile number at a certain pixel coordinate with the Map's .getTile() method. E.g.:

update: function() {
	this.parent();
	
	var t = ig.game.collisionMap.getTile( this.pos.x, this.pos.y );
	if( t == 1 ) {
		// ...
	}
}
Page 1 of 1
« first « previous next › last »