Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /**
- * Find the index of the tile at given position.
- * Result is -1 if the point is outside map.
- *
- * @param Point A point in world coordinates.
- * @return An Int containing the index of the tile at this coordinate. -1 if no tile were found.
- */
- public function getIndexFromPoint(Point:FlxPoint):Int
- {
- //Calculate corrected mouse position
- var x0 = Point.x - heightInTiles * _scaledTileWidth * 0.5 - x;
- var y0 = Point.y - y - _scaledTileHeight;
- //Calculate coordinates
- var floatrow = y0 / _scaledTileDepth - x0 / _scaledTileWidth;
- var floatcol = y0 / _scaledTileDepth + x0 / _scaledTileWidth;
- if (floatrow < 0 || floatcol < 0)
- return -1;
- var col = Std.int(floatcol);
- var row = Std.int(floatrow);
- //Check if the coordinates are valid
- if (row >= heightInTiles || col >= widthInTiles)
- return -1;
- //Finally compute the index
- return row * widthInTiles + col;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement