Hello,
So I have a way to click a startTile and a goalTile based off where you click and pressing LShift or LCtrl.
I used Num1 (view.zoom(1.1)) and Num2 (view.zoom(1.1)) to zoom in and out of the 250x250 (64x64) map.
const auto mousePos = sf::Mouse::getPosition();
const auto pixelToCoordPos = m_pGame->getWindow().mapPixelToCoords(mousePos,view);
const sf::Vector2f tilePosFromMouse = {pixelToCoordPos.x / 64,pixelToCoordPos.y/64};
When I click somewhere, the tiles are off. But when I maximize the window, it all of sudden goes to the right tile. But when I zoom out it is off a few tiles on the Y-axis (undershoots it).
if (sf::Mouse::isButtonPressed(sf::Mouse::Left)) {
if(sf::Keyboard::isKeyPressed(sf::Keyboard::LShift)) {
if (currentNode != nullptr) {
auto currTile = m_map->getTile(tilePosFromMouse.x, tilePosFromMouse.y);
currentNode = currTile;
m_map->setStartNode(currTile);
}
}
Tile* Map::getTile(int columnIndex, int rowIndex)
{
if (tileIsValid(columnIndex, rowIndex)) {
return &m_grid[columnIndex][rowIndex];
}
else {
return nullptr;
}
}
Any idea how I can correct this? Hope I explained the situation correctly.
Thanks!