hello again.
I should have said this before but I have class Engine which has "update" method.
I have changed few things and now it looks like this:
void CEngine::run()
{
while (window->isOpen())
{
handleEvents()
update(m_deltatime.getElapsedTime());
m_deltatime.restart();
render();
}
}
void CEngine::update(sf::Time deltatime)
{
m_player->update(deltatime.asSeconds());
}
Player "update" method:
void CPlayer::update(float deltatime)
{
if (sf::Keyboard::isKeyPressed(sf::Keyboard::Up))
{
m_sprite.setTextureRect(sf::IntRect(42, 0, 42, 42));
m_vel.y = -169;
}
if (sf::Keyboard::isKeyPressed(sf::Keyboard::Down))
{
m_sprite.setTextureRect(sf::IntRect(0, 0, 42, 42));
m_vel.y = 169;
}
if (sf::Keyboard::isKeyPressed(sf::Keyboard::Left))
{
m_sprite.setTextureRect(sf::IntRect(84, 0, 42, 42));
m_vel.x = -169;
}
if (sf::Keyboard::isKeyPressed(sf::Keyboard::Right))
{
m_sprite.setTextureRect(sf::IntRect(126, 0, 42, 42));
m_vel.x = 169;
}
if ((m_vel.x != 0) && (m_vel.y != 0)) m_vel /= sqrt(2.f);
m_sprite.move(m_vel.x*deltatime, m_vel.y*deltatime);
if (m_vel.x != 0) m_vel.x = 0;
if (m_vel.y != 0) m_vel.y = 0;
}
Slight difference, maybe I have to live with that