SFML - Sprite position and movement
Oh, and one last thing, how can I do so my player can move diagonally when UP and RIGHT are pressed for example. I'm not keen on just having 4 direction movement. I have tried using && to check for both keys, but it doesnt work.
This is a copy of my CheckInput() method from my Smash PC Game (detailed in my old Blog, linked in my Signature). It will set the velocity of the player depending on the keys pressed (and it handles diagonal), as well as faces the player towards the mouse using SFML. It uses atan2 to find it based on the location of player and mouse, not a vector.
Also, assume Utilities::KeyIsDown(), just checks a sf::Input::IsKeyDown() or IsMouseButtonDown()
Good answer BeerNuts, I was expecting a simple concept, but by looking at your code, I can actually see how you have done the movement by having cummulative x and y forces.
Anyways, can anyone actually answer my first problem ( how to get the real position of the object relatively to the game window ) as the normal functions aren't doing the work
Good answer BeerNuts, I was expecting a simple concept, but by looking at your code, I can actually see how you have done the movement by having cummulative x and y forces.
Anyways, can anyone actually answer my first problem ( how to get the real position of the object relatively to the game window ) as the normal functions aren't doing the work
sf::Spirte::getPosition returns the absolute position of the sprite in the world - not necessarily the window. The window displays a sf::View - which is normally exactly the size of the window.
Bottom line, sf::Sprite::getPosition should return the position. Perhaps if you post your code we could see what else could be affecting it. (in SFML2 there's an origin which can affect position)