So i have to move a sprite that orbits around the center of the screen (which is the original position of the object in X) while moving down. I have yet to find the way to get it to work, since the sprite flickers everywhere around the screen.
move(0, speed);
angle = getRotation();
rotate(+1);
move(origPosX + cosf(angle) * speed, origPosY + sinf(angle) * speed);
I can only assume you're running the code in your question every frame, in which case, you should be using setPosition
, not move
, otherwise it will be adding the position offset for the rotation constantly.
You also add 1 to the rotation every frame, which unless you lock your framerate, is going to be inconsistent, so I recommend multiplying by the time since last frame (AKA "delta time").
Also, rotation in SFML is done in degrees, but cosf
takes arguments in radians, so you need to convert that.
You want to do something like this:
position += sf::Vector2f(0.f, speed);
rotate(1.f * deltaTime);
setPosition(position.y + cosf(toRadians(angle)), position.y + sinf(toRadians(angle)));