So.. im still not 100% sure what part you want..
So, this is a compleate (if a bit hacky) way to rotate, accelerate, and move a space ship (m_Ship)
In my example I just use a ractangeShape for the ship, but you can use a sprite just fine.
you will need the values.
float m_xVel = 0, m_yVel = 0, m_accel = 0.01;
hidden somewhere where MoveShip can accec them.
the x and y Val is the current speed that the ship is moving at the x and y axis.
the m_accel is how fast it accelerates in a given direction.
in addition you will need a sf::Keyboard m_Key
This can be done differently, but for this short code that is all i made.
//in the header//
float m_xVel = 0, m_yVel = 0, m_accel = 0.001;
sf::Keyboard m_Key;
//In the class//
void Game::MoveShip() {
//Rotate right and left
if (m_Key.isKeyPressed(sf::Keyboard().Right)) {
m_Ship.setRotation(m_Ship.getRotation() + 1);
}
if (m_Key.isKeyPressed(sf::Keyboard().Left)) {
m_Ship.setRotation(m_Ship.getRotation() - 1);
}
//Accelerate the ship forward.
if (m_Key.isKeyPressed(sf::Keyboard().Up)) {
m_xVel += (cos(m_Ship.getRotation() / 180 * 3.1415)) * m_accel;
m_yVel += (sin(m_Ship.getRotation() / 180 * 3.1415)) * m_accel;
}
//Make the actual movement of the ship.
m_Ship.setPosition(m_Ship.getPosition().x + m_xVel, m_Ship.getPosition().y + m_yVel);
}
this code will rotate the ship and move it around using the Up, Right and Left button.
the first two If statements simply looks for pressing the Right and Left key. and apply rotation to the ship accordingly.
the third, as the first two looks for a key press, but this time the up key.
if the up key is pressed, it grasp the current rotation, and using cos and sin, it calculates how much to add to the ships x and y speed (velocity).
note that the ships rotation is divided by 180*PI, the reason for this is that SFML rotation uses 360 degree rotation, where the math con and sin is geard towards radiant (rotation = 0-1)
In this case, a rotation of 0 or 360 is horizontal fazing right.
This will give you movement like in the asteroids games where your ship will float around in whatever direction until it is accelerated in another direction.
i Hope that helps.
if you want the full code to look over, i can upload that somewhere.