You're looking for Game States or a State Machine (google's your friend).
In pseudo-not-working code, it looks like :
class State
{
public:
virtual void handleEvents() = 0; // handle player, world events
virtual void update() = 0; // do the logic
virtual void render() = 0; // draws on screen
private:
sf::Window& mWindow;
};
// Inherit from State to do some MenuState, GameState, GameOverState and stuff
class Game
{
public:
void changeState(State* state);
void play()
{
mState = new MenuState(this);
while(mWindow.isOpen())
{
mState->handleEvents();
mState->update();
mState->render();
}
}
private:
sf::RenderWindow mWindow;
State* mState;
};
This would be a *very* simple implementation of States. You will probably need to give states more data (a context about your app), make pointers be smart, etc.
Have a look at the book SFML "Game Programming", there's such a thing implemented. Sources are available on GitHub (you'll find the link to the repo somewhere on the forum).
You mean state as the state of physics as Glenn wrote? If so, I think it wouldn't be that hard to implement. Just make sure that the elements you use to describe actual data (vectors for position, quaternions for orientation) would implement lerp/slerp (e.g. sf::Vector2 c = lerp(a,b, alpha); for vectors a and b). You certainly would have to preserve the previous state in your game objects. So if there is an object which sprite's being moved, you would save two positions inside the object's instance.
A quick and dirty try on this (can certainly be improved ;) ):
sf::Vector2 lerp(const sf::Vector2& a, const sf::Vector2& b, float alpha)
{
return sf::Vector2(a * alpha + b * (1.0f - alpha));
}
class GameObjectInstance
{
public:
void UpdateLogicPos(sf::Vector2& offset)
{
oldPos = actualPos;
actualPos += offset;
};
void UpdateRenderPos(float alpha)
{
mySprite.setPosition(lerp(oldPos, actualPos, alpha));
};
sf::Sprite& Sprite()
{
return mySprite;
};
private:
sf::Sprite mySprite;
sf::Vector2 oldPos;
sf::Vector2 actualPos;
};
// main drawing loop
// ..
for (auto goi : myObjects)
{
goi.UpdateRenderPos(currentFrameAlpha);
window.draw(goi.Sprite());
}
// ..