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

Show Posts

This section allows you to view all posts made by this member. Note that you can only see posts made in areas you currently have access to.


Messages - alacrity

Pages: [1]
1
General / Rotating a drawing from its center
« on: January 14, 2024, 04:51:24 pm »
I've tried looking for someone having a similar issue to me, and could not find anything close.
I am trying to create a basic geometry dash copy, and I am having a lot of issues rotating my player square. I am able to rotate it in mid air, just like in geometry dash, but it is rotating with the origin being the top left of the square. This causes a couple of issues for me, but I am only looking to find a solution as to how I can get the origin of rotation to be the center of the square, allowing me to jump and rotate in place. Here is the code and a short gif of the behaviour:
if (!onGround) {
    // Set the origin to the center of the player for rotation
    squarePlayer.setOrigin(0.5f * squarePlayer.getSize());

   float rotationFactor = 180.f * velocityY / sqrt(2.f * jumpHeight * gravity);
    squarePlayer.setRotation(rotationFactor);

    // Draw the player square
    window.draw(squarePlayer);

   // Reset the origin back to the top-left corner after rotation
    squarePlayer.setOrigin(sf::Vector2f(0, 0));
}
else {
    // Draw the player square without rotation
    window.draw(squarePlayer);
}
https://gyazo.com/654f9d56330c5af892cafce09c3eac73

Pages: [1]