public FSprite getTileAt(float givenX, float givenY)
{
if (!_skipZero) {
int node = (int)((_tilesWide % Mathf.Floor(givenX / _tileWidth)) + Mathf.Floor(givenY / _tileHeight) * _tilesWide);
if (node < _tilesWide * _tilesHigh) {
return _childNodes[node] as FSprite;
} else {
Debug.Log ("FTilemap: index [" + node + "] outside of range: " + (_tilesWide * _tilesHigh));
return null;
}
} else {
float checkX = Mathf.Floor(givenX / _tileWidth);
float checkY = Mathf.Floor(givenY / _tileHeight);
// loop through the available sprites
foreach (FNode sprite in _childNodes) {
float compareX = Mathf.Floor((sprite.x - _tileWidth/2) / (float)_tileWidth);
float compareY = -Mathf.Floor((sprite.y + _tileHeight/2) / (float)_tileHeight);
if (checkX == compareX && checkY == compareY) {
return sprite as FSprite;
}
}
Debug.Log ("FTilemap: index [" + checkX + ", " + checkY + "] not found.");
return null;
}
}