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 dryas

Hi,

I'm writing a puzzlegame where you need to place some items on a playfield. The playfield is done via Weltmeister as a normal map. But how can I dynamically add some entities to the field located on the grid cell where the user has touched his device? Is there some kind of event like hastouched(x,y) and I need to calculate the gridposition by my own? Or is there something different?

Thanks for any help,

Benny

1 decade ago by lTyl

You can calculate which map tile the player is touching very easily:
var tileX = entity.pos.x / tilesize,
tileY = entity.pos.y / tilesize;
return {x: tileX, y: tileY};

Where tilesize is the size of a single tile from your spritesheet. To figure out where a player clicked/touched, an easy way is to create a simple 'touch' entity. All you do is set the position of the entity to the location where the player clicked/touched, and then use that entity to do the calculation above.

To snap a new entity to a grid on the map you would reverse the calculation above:
entity.pos.x = tileX * tileSize;
entity.pos.y = tileY * tilesize;
Page 1 of 1
« first « previous next › last »