1
General / Re: Frame-speed on animation
« on: June 28, 2017, 10:06:23 am »
So I tried my best to follow what you said.
This is how it is now:
It is indeed working as intended. But shouldn't I utilize getElapsedTime() instead? I guess it's there for a reason. Have to keep reading c++ books to understand more.
Sorry for writing with honestly not enough knowledge. Have to start somewhere I guess.
Cheers.
This is how it is now:
Code: [Select]
void Animation::Update(sf::Sprite& p_sprite, sf::Time &p_time)
{
m_elapsed = p_time.asSeconds();
if (m_active) {
m_frameCounter += m_frameSpeed * m_elapsed;
}
std::cout << "frameCounter: " << m_frameCounter << std::endl;
if (m_frameCounter >= m_frameSpeed) {
//m_elapsed = 0.0f;
m_frameCounter = 0;
m_currentFrame.x += m_frameSize.x;
if (m_currentFrame.x >= p_sprite.getTexture()->getSize().x) {
m_currentFrame.x = 0;
}
}
p_sprite.setTextureRect(sf::IntRect(m_currentFrame.x, m_currentFrame.y, m_frameSize.x, m_frameSize.y));
}
It is indeed working as intended. But shouldn't I utilize getElapsedTime() instead? I guess it's there for a reason. Have to keep reading c++ books to understand more.
Sorry for writing with honestly not enough knowledge. Have to start somewhere I guess.
Cheers.