Jump to content
  • Advertisement
Sign in to follow this  

Tilemap Location

This topic is 4557 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

Hello! I was just going to post asking a question, but then I decided to use my initiative and find out the answer myself.
    float pos = 144;
    float tile_width = 100;
    int coord;
    if (pos >= 0) {
        coord = (int)(pos/tile_width);
        coord = (int)(pos/tile_width) - 1;
Is this correct for finding the current coordinate you are in a tilemap? Seems to work - could anyone who has done a tile engine confirm it is the correct way? The problem was I didn't know if negative numbers rounded up or down... they seem to go up. Cheers... :D

Share this post

Link to post
Share on other sites
If your tile width was 100, and your position on the X axis was 144, you would be in the second tile. So you need to allow for the fact that anything over that width is the next tile over.

Your code would end up giving coord a value of one because the cast to integer truncates the extra bit you need.

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!