Jump to content
  • Advertisement
Sign in to follow this  
Lith

Align something to a grid

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

If you intended to correct an error in the post then please contact us.

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 this post


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

Something like that ...

Share this post


Link to post
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 this post


Link to post
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)?

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!