Jump to content
  • Advertisement
Sign in to follow this  
Drakkcon

*solved* How to get X,Y coords when only given an index number

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

I can't seem to figure this out. My tileset class has a tileSheet image, and I want to write a function that allows me to retrieve a tile from the tileSheet given only an index integer. The problem is, the tileSheet is a square, not a line so I have to convert the index value to X,Y coordinates. Can anyone tell me how to do this? [Edited by - Drakkcon on September 13, 2005 7:07:32 PM]

Share this post


Link to post
Share on other sites
Advertisement
You have to know the width, after this, assuming x, y and the index start at 0, you have :

y = index / width (integer division)
x = index % width

Share this post


Link to post
Share on other sites
That's perfect, I was pulling my hair out over that :)
It seems I always forget about that little old modulus.

Thanks man!

Edit: I would rate you up, but I already have.

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!