I'm not sure what more to say, so I'll write some psudocode to show what I mean:
//some kind of update step called at a constant rate
void update()
{
//move player useing whatever control scheme you have
// eg. if(keypress.w) player.move(forward) or just pass your sf::events into the physics system
//store the main views current position
sf::Vector2 oldviewpos = playerView.getPosition();
//move the main view to the position of the player so that we remain focused on them
playerView.setPosition(playerpos);
//create vectors pointing from the old views position to the new player position,
//this gives us a direction in which to move
sf::Vector2 moveVector = player.getPosition() - oldviewpos;
//move the background views by this move vector,reduce them all by a variable amount so that
//that they all move at different but slower rates, this could be done using any math you like
//I'm doing it here by dividing them
backgroundview1.move(moveVector / 2);
backgroundview2.move(moveVector / 3);
backgroundview3.move(moveVector / 4);
}
Then simply draw each layer using whichever view is appropriate. eg draw the player and game relevant stuff using the main view and each of the background layers using one of the background views.
I'm not sure what more to say, so I'll write some psudocode to show what I mean:
//some kind of update step called at a constant rate
void update()
{
//move player useing whatever control scheme you have
// eg. if(keypress.w) player.move(forward) or just pass your sf::events into the physics system
//store the main views current position
sf::Vector2 oldviewpos = playerView.getPosition();
//move the main view to the position of the player so that we remain focused on them
playerView.setPosition(playerpos);
//create vectors pointing from the old views position to the new player position,
//this gives us a direction in which to move
sf::Vector2 moveVector = player.getPosition() - oldviewpos;
//move the background views by this move vector,reduce them all by a variable amount so that
//that they all move at different but slower rates, this could be done using any math you like
//I'm doing it here by dividing them
backgroundview1.move(moveVector / 2);
backgroundview2.move(moveVector / 3);
backgroundview3.move(moveVector / 4);
}
Then simply draw each layer using whichever view is appropriate. eg draw the player and game relevant stuff using the main view and each of the background layers using one of the background views.
Riiiight I see! Thats a very good idea. That way if my player hits something etc etc the background will actually slow/stop as its in reference to my position. Brilliant! I will get to it.
Another thing.. how do you think I should handle the size of the backgrounds? Obviously making a massive background image would be silly, so should I make a large image in photoshop and extract it into tiles? Then display it as tiles? Whats your advice here?
Cheers!