/// <summary> /// Converts the given world space position to a PositionI /// </summary> /// <returns>PositionI of the given world space.</returns> /// <param name="point">Point which should be converted.</param> /// <param name="worldLayer">World layer.</param> public static PositionI WorldspaceToPositionI(CCPoint point, WorldLayerHex worldLayer) { var regionPos = WorldspaceToRegion(point); var startRegionPoint = RegionToWorldspace(regionPos); var regionView = worldLayer.GetRegionViewHex(regionPos); if (regionView != null) { var tileCoord = regionView.GetTileMap().LayerNamed(ClientConstants.LAYER_TERRAIN).ClosestTileCoordAtNodePosition(point - startRegionPoint); tileCoord.Row = Math.Max(tileCoord.Row, -tileCoord.Row); tileCoord.Column = Math.Max(tileCoord.Column, -tileCoord.Column); var cellPos = new CellPosition( tileCoord.Column % Constants.REGION_SIZE_X, tileCoord.Row % Constants.REGION_SIZE_Y); return new PositionI(regionPos, cellPos); } return null; }