Welcome, Guest. Please login or register. Did you miss your activation email?

Author Topic: Object positioning problem  (Read 1448 times)

0 Members and 1 Guest are viewing this topic.

Tixik

  • Newbie
  • *
  • Posts: 2
    • View Profile
Object positioning problem
« 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.
« Last Edit: February 12, 2013, 05:18:26 pm by Tixik »

krzat

  • Full Member
  • ***
  • Posts: 107
    • View Profile
Re: Object positioning problem
« Reply #1 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());
SFML.Utils - useful extensions for SFML.Net

Tixik

  • Newbie
  • *
  • Posts: 2
    • View Profile
Re: Object positioning problem
« Reply #2 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.

 

anything