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 Elvar

Hey developers.

As stated in a previous thread, i am currently working on a TD, in my game, you are to buy towers from a menu, after selecting a tower from the menu, it follows the mouse.
This works great, but i want the tower to snap to the grid, as the player moves the mouse, how should i approach this?
I thought i could get the tile, using the getTile method, but this seems only to work on collisionMap returning 0 or 1 only.

Best regards
Elvar

1 decade ago by Heartless49

It can be done by calculating the mouse's position and rounding it to the nearest tile-size.

Something like this...

var xTile = (ig.input.mouse.x/this.tileSize).round();
this.pos.x = xTile*this.tileSize;
var yTile= (ig.input.mouse.y/this.tileSize).round();
this.pos.y = yTile*this.tileSize;

That would check the mouse's position, and then calculate the nearest tile-size increment on the map, and set the entity position to that tile's coordinates.

1 decade ago by Elvar

Thanks Hearthless49, works like a charm!

1 decade ago by Heartless49

No problem, ^^
Page 1 of 1
« first « previous next › last »