Fix view movement problems.

This commit is contained in:
Luca Apolzan 2023-09-23 12:40:01 +03:00
parent 4c7ec32cf4
commit 634c1a0fd6
2 changed files with 6 additions and 3 deletions

View File

@ -140,4 +140,4 @@ void GamePreview::OnUpdate()
// Update last mouse position
m_lmx = relativePosition().x;
m_lmy = relativePosition().y;
}
}

View File

@ -93,7 +93,10 @@ int Engine::GetFrame()
sf::Vector2i Engine::GetTileMapOffset()
{
return sf::Vector2i(m_tilemap.getPosition());
sf::Vector2f viewCenter = m_view.getCenter();
sf::Vector2f halfExtents = m_view.getSize() / 2.f;
sf::Vector2f translation = viewCenter - halfExtents;
return sf::Vector2i(-translation);
}
void Engine::Move(int state)
@ -170,4 +173,4 @@ void Engine::Render()
m_texture->draw(m_plr);
m_texture->display();
r = 0;
}
}