-
[RESOLVED] finding xy from the given number of a tile?
I've set up a simple grid of lets say of 4 x 4, and number each tile accordingly:
0 1 2 3
0 '00''01''02''03'
1 '04''05''06''07'
2 '08''09''10''11'
3 '12''13''14''15'
I need to then find the x and the y values based on the tile number? So say I'm given tile 11, I need two equations, one to find its x value(3), and another the y value(2). I'm sure this must be pretty simple stuff, but I'm completely stuck at the moment! thanks.
-
I worked out a solution that seems to work:
x = value - ( RoundDown(value/sale) *scale)
y = RoundDown(value/scale)
where scale in this example is 4. Is there a better formula I could use?
-
Senior Member
Your way of finding y is the only way. As for x, I think you're looking for the modulo % operator.
Code:
scale = 4
x = value%scale;
y = Math.Floor(value/scale);
-
nice one, I didn't know about modulo % operator - sounds pretty useful
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|