Page 1 of 1

Orhographic to Isometric coordinates

Posted: Sun Nov 06, 2016 6:19 pm
by 0x29a
Hi there!

I'm having trouble with translating tile coordinates from 2D table to screen X,Y values.

Table I have represents a dungeon, like in a roguelike game. It has regular Map[rows][columns] structure, with each field representing either floor tile, a wall, or something else.

I'm using diamond-shaped tiles for the floor. Everything else will have diamond-shape base, too.

Algorithm I'm currently using looks like this:

Code: Select all


function map_to_iso(field, tile_width, tile_height)

	x = (field.x - field.y) * tile_width/2;
	y = (field.x + field.y) * tile_height/2;
	return x,y
	
end



Code is problematic, because very often column of a field is less than it's row, resulting in negative x value. It gives me borked results, like here: https://i.imgsafe.org/f72daf08c3.png

If I add some large value to every x, functionally moving everything to the right, then I get proper results, but I also get huge void with a little map in the middle. I also encounter lots of translation problems when it comes to making it work with Gamera lib. Essentialy I can't move it around to focus on proper place.

How do I tackle those problems?
Thanks in advance for help!

Re: Orhographic to Isometric coordinates

Posted: Sun Nov 06, 2016 6:40 pm
by raidho36
Math doesn't changes the way it works around the edges, there is probably an error elsewhere in the code.