SFML community forums

Help => General => Topic started by: Tixik on February 12, 2013, 05:16:18 pm

Title: Object positioning problem
Post by: Tixik on February 12, 2013, 05:16:18 pm
Hi, so i have this Mario-like game...
main loop looks like

View view;
while(window.isOpen())
{
marioData.updatePlayer(View & view);
gameData.updateScore(View & view);
}

Please note that score and player are in different classes...
updatePlayer(View & view) just moves player left/right, depends on button pressed, and as the player moves, the view moves aswell - hence the view reference

updateScore(View & view) does this...
score_string.setPosition(700 + (view.getCenter().x - WIDTH/2 ) , 5);

where 700 and 5 are the on screen coords, but as the view moves, it has to move aswell in order to stay in the same place, that's when view.getCenter().x - WIDTH/2 comes into play , calculating x coord of view - screen width/2.

and my problem with this is that when i press the Left/Right button, the player, view and score moves, but score jumps like 10 pixels left/right, depends on the key pressed and stays 10pixels more left/tight than it should be, until the key is released and neither left and right key is pressed then it stays at correct position.

Please, I'm lost with this, what have I done wrong? Or is there a better way to make Score have absolute position on screen? Thanks in advance.
Title: Re: Object positioning problem
Post by: krzat on February 12, 2013, 05:41:33 pm
Use two views, first for world, second for interface.
Also, don't send view to player: just set it in your game loop: view.setCenter(marioData.getPosition());
Title: Re: Object positioning problem
Post by: Tixik on February 12, 2013, 06:08:03 pm
Thanks a lot, turned out I missunderstood the use of view, I first rendered the objects and then applied the view, so It got the coords from previous state of view,but your solution is much better anyways.