# Align something to a grid

This topic is 2997 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

## Recommended Posts

How would you align something to a grid? I need to know this because i am making a level editor for my game, and i want the map to be in a 16 by 16 grid, so when the user places a tile it need's to be aligned with a grid. How would you do it?

##### Share on other sites
snapPosition = Vector2<int>( static_cast<int>( std::floor( mouseX / tileSize ) ), static_cast<int>( floor( mouseY / tileSize ) ) );

Something like that ...

##### Share on other sites
You probably want to use round', not floor'. If you don't have round', you can write it like this:
double round(double x) {  return std::floor(x+.5);}`

##### Share on other sites
It depends... Are the tiles' centers snapped to grid intersections (round) or are the tiles' top-left corner is snapped to grid intersections (floor)?