[SDL] isometric mouse mapping problem
antonmaster at mail.ru
Sat Feb 25 09:57:06 PST 2006
I was writing something like isometric tile engine and had the famous problem: mouse mapping =).
Well i do it by comparing the colors of the mouse tile ( you know, this isometric diamond with read yellow green and blue corners)
But there is a problem. Maybe its some getting pixel error, i dont know.
Here is the code:
int x, y;
Uint8 r, g, b;
x = Cursor.x / TILE_WIDTH;
y = Cursor.y / TILE_HEIGHT;
offset.x = Cursor.x - (x * TILE_WIDTH);
offset.y = Cursor.y - (y * TILE_HEIGHT);
raw_pixel = (Uint16 *) mousemap->pixels;
of = mousemap->pitch / 2 * offset.y + offset.x;
pixel = raw_pixel[of];
SDL_GetRGB(pixel, mousemap->format, &r, &g, &b);
Its not the complete code, but error is somewhere here. It doesnt get the right color.
Thanks for any help.
More information about the SDL