Jump to content

  • Log In with Google      Sign In   
  • Create Account

14 years ago on June 15th Gamedev.net was first launched! We want to thank all of you for being part of our community and hope the best years are ahead of us. Happy birthday Gamedev.net!

#ActualTrienco

Posted 20 April 2012 - 12:24 PM

Essentially copy/pasted from my code and changed to 360 for your tile size... don't ask... I spent an entire evening drawing tiles and solving equations... should have written some comments instead of thinking I'd never forget how I got there.

Vector3 screen2World(int x, int y)
{
	return Vector3(scroll.x + x/zoom, scroll.y + y/zoom, 0);
}

Vec2 world2Tile(float x, float y)
{
	return Vec2( (int)(x + 2*y) / 360, (int)(2*y - x) / 360 );
}

//The top left corner of the bounding box of the diamond shaped tile (ie. where you want to draw the tiles sprite)
//By reversing this you get the formula above
Vector2 tile2World(int x, int y)
{
	 return Vector2((x - y) * 180, (x + y) * 90);
}

#1Trienco

Posted 20 April 2012 - 12:16 PM

Essentially copy/pasted from my code and changed to 360 for your tile size... don't ask... I spent an entire evening drawing tiles and solving equations... should have written some comments instead of thinking I'd never forget how I got there.

Vec2 world2Tile(float x, float y)
{
    return Vec2( (int)(x + 2*y) / 360, (int)(2*y - x) / 360 );
}

Vector3 screen2World(int x, int y)
{
    return Vector3(scroll.x + x/zoom, scroll.y + y/zoom, 0);
}

PARTNERS