Hi! This is my first question in the forum as I'm new in SFML. I usually use Libgdx as 2d gamedev framework and I wanted to start coding games in C++. In Libgdx there's a method call render(), where you get the input, do updates and then render, all in the same method, but in a specific order.
Now I have this nice game loop that I've learnt from the book SFML Game Development:
void Game::run(){
sf::Clock clock;
sf::Time timeSinceLasUpdate;
while(this->renderWindow.isOpen()){
this->handleEvents();
timeSinceLastUpdate += clock.restart();
while(timeSinceLastUpdate > this->timePerFrame){
timeSinceLastUpdate -= this->timePerFrame;
this->handleEvents();
this->update(this->timePerFrame);
}
this->render();
}
}
Where timePerFrame is 1.f/fps, and in my case fps=60.f.
Where handleInput() is a method that detects the input of the player (mouse and keys)
Where update() is the method to update positions of player...
Where render() is the method that draws on screen.
Here is my question, given my game loop (btw, if there's any problem with it, pls tell me), where should I calc if entities are colliding and the physics? It's better in the handleInput, update or render?
I think handleInput is not really the method where it should be calculated, but due to the frame I've been using, I'm not too sure.
Thanks!