123
-=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- (c) WidthPadding Industries 1987 0|663|0 -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=-
Socoder -> On Topic -> pixel checking using tiles?

Mon, 23 Feb 2009, 17:17
spinal
It's late and I cant think...

If i have an x and y value (in pixels), i can find my 16x16 pixel tile number from my map, like so...

int tile = test_map[(x>>4)+64*(y>>4)];

so far, so good...

As im working on a system that only allows 8x8 tiles, these 16x16 tiles are made up of 4 of them, i can find these 4 tile numbers like so... (thanks to jay)

int m=((tile % 16)*2)+((tile / 16)*64);

so my 16x16 tile is made up like this...


but what im getting stuck on is...

how do i find which of the 8x8 tiles my x,y falls into, and how far into it i am?


-=-=-
Check out my excellent homepage!
Mon, 23 Feb 2009, 18:01
Jayenkai
OK.. Assume you've the following

Map


And each one is 16x16 away from each other.

At 8x8 pixels, you're slap bang in the middle of 0x0.
At 64x64 you're over in the corner of 3x3 |edit| Well, ok, 63x63! |edit|

So, map reference from pixel = floor(Map/16)
MapX=floor(PixelX/16);
MapY=floor(PixelY/16);

(Floor requires that you #include <math.h>)

Pluck that tile from the map array, and you've got your target.

Then you just grab the offset on that particular tile, which is your basic "%" remainder..

TilePixelX=(PixelX % 16);
TilePixelY=(PixelY % 16);

You should be able to use those values to pluck exactly the right pixel from just the right map tile..

Sorted!!

-=-=-
''Load, Next List!''