Hey guys
Im trying to get a sprite to stay in the top left corner, now im using a view like so
mainView.setCenter(512,384);
mainView.setSize(1024,768);
Now the red square is the player and the player is the center so i set up my view like so
mainView.setCenter(sf::Vector2f(player.pos.x+15,player.pos.y));
but im having some problems, i have a image that i want to go in the top left corner.
so i try this
interBtns.pos.x = v2.x;
interBtns.pos.y = v2.y;
now this puts it in the bottom, but how would i work it out so it will go to the top left corner? the screen resoultion is 800 by 600
[attachment deleted by admin]
I'm not sure if you've seen my tutorial on sf::View (https://github.com/SFML/SFML/wiki/TutorialUsingView), it should give you some insight on how to use views.
To position your sprite you could use convertCoords().
interBtns.pos = window.convertCoords(sf::Vector2i(0, 0));
Use again convertCoords()! ;)
sf::Vector2f mouseViewPos = window.convertCoords(sf::Mouse::getPosition(window));
Ok this is what i have, the icon is in the top left corner but its abit delayed from the players movement, I think i have the update in the wrong place but i can sort that out later.
but this is what i have for the position
sf::Vector2f v2 = screen.convertCoords(sf::Vector2i(10, 10));
interBtns.pos.x = v2.x;
interBtns.pos.y = v2.y;
in my collision detection i have this
sf::Vector2f mouseViewPos = screen.convertCoords(sf::Mouse::getPosition(screen));
if(math.pointInRect(mouseViewPos.x,mouseViewPos.y,int(interBtns.pos.x),int(interBtns.pos.y),interBtns.pos.w,interBtns.pos.h) == true)
{
cout << "correct" << endl;
}
the math just finds out if a point is inside a rectangle.
I still have a little problem with drawing
Lets say my player is falling, my buttons start to move downwards but they are maybe a few pixels off, why arent they just staying static?
here is a piece of update code
player.update();
mainView.setCenter(sf::Vector2f(player.pos.x+15,player.pos.y));
screen.draw(interBtns.icon);
sf::Vector2f v2 = screen.convertCoords(sf::Vector2i(10, 10));
interBtns.pos.x = v2.x+(80);
interBtns.pos.y = v2.y;
interBtns.update();
Okay a better way to draw static objects is to have a second view, that doesn't get changed. So you got one view represents the game and can get moved in all directions and you have a view that is static and you can render to it all your GUI elements etc.
Now before you draw your things you can just change the views:
window.setView(game);
window.draw(object);
//...
window.setView(fixed);
window.draw(gui);
Also PM stands for Personal Message, so as long as you don't have anything to say personally, please don't write me there.
If you need help even faster, then I can only advice you to join the unofficial IRC channel (http://en.sfml-dev.org/forums/index.php?topic=2997.0). ;)