Welcome!

Join our community of MMO enthusiasts and game developers! By registering, you'll gain access to discussions on the latest developments in MMO server files and collaborate with like-minded individuals. Join us today and unlock the potential of MMO server development!

Join Today!

[AS3] Converting XY Coordinates to Isometric Coordinates

Ask me about Daoism
Loyal Member
Joined
Nov 6, 2010
Messages
1,560
Reaction score
393
Hello /f(12^2)/!

I'm working on a small isometric game, but I'm having trouble converting the X/Y coords to the proper map coords.


The current method I'm using has major flaws, and I was wondering if someone had some code, a formula, or an explanation on how to get the proper tile. I can't simply add an event listener to each tile because all sprites are rectangular and will overlap with others, yielding the wrong result.

To create the grid, I use..

Code:
for (var isoY:int = 0; isoY < mapArray.length; isoY++)
			{
				for (var isoX:int = 0; isoX < mapArray[isoY].length; isoX++)
				{
					if (this.mapArray[isoY][isoX] == 1)
					{
						var _tile:Tile = new Tile();
						_tile.x = XOffset + (isoX * ((_tileWidth / 2) - 1) - (isoY * ((_tileWidth / 2) - 1)));
						_tile.y = 2 + (isoX * int(_tileHeight / 2) - 1) + (isoY * int(_tileHeight / 2) - 1);
						addChild(_tile);
						
						this.tileArray[isoY][isoX] = _tile;
					}
				}
			}

Any help is appreciated.
 
Joined
Jun 23, 2010
Messages
2,318
Reaction score
2,195
Can't you just use the "tileArray" with your X/Y?

A sprite has an inherited object container, meaning you can use addChild on your sprites to add sub sprites.
The x/y cords (0, 0) would translate as offsetx/y of the parent sprite.

Example:
sprite #1 (x = 10, y = 25)
sprite #2 (x = 20, y = 20)

sprite #1 .addChild(sprite #2 )

the cords of sprite #2 would be x = 30, y = 45
 
Ask me about Daoism
Loyal Member
Joined
Nov 6, 2010
Messages
1,560
Reaction score
393
Can't you just use the "tileArray" with your X/Y?

A sprite has an inherited object container, meaning you can use addChild on your sprites to add sub sprites.
The x/y cords (0, 0) would translate as offsetx/y of the parent sprite.

Example:
sprite #1 (x = 10, y = 25)
sprite #2 (x = 20, y = 20)

sprite #1 .addChild(sprite #2 )

the cords of sprite #2 would be x = 30, y = 45

I've thought of this, but since all sprites are rectangular, the corners of the main sprite wouldn't trigger the event (if I understand correctly)
 
Back
Top