-
-
Notifications
You must be signed in to change notification settings - Fork 175
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
pygame.transform.rotate_center #3378
Comments
Can you show me a result surface rotating normally and a result surface rotating like this? in my mind they would produce the same result, so I'm having a hard time justifying this in my mind |
oh wow, damn, wow, I support this, sure |
Mark the corners of your sprite and you'll see why it behaves like this. @ScriptLineStudios I have no clue how would you like it to work. Cut out the parts that are outside the original rect? Why would it be useful? This works in your case only because the image is closely shaped to a circle... |
@gresm you have a point, and additionally, isn't the sprite on the left being slightly cut off? like when the horizontal parts need to start rotating, or is it just me? when I first saw it I was a bit mesmerized, but I think that to achieve something close to the image of the left without cutting out anything one can use the Mask class and find the bounding rect and then cut, or cut just like you said. |
Technically The suggested function would be more like a "cropped" version of pygame.transform.rotate_cropped(surface: Surface, angle: float) -> Surface |
If we are going to expand on rotate I would just make a generic rotate_on_pivot function where the pivot point can be changed as needed. This is what I use, its a bit different in that it returns a rect as well but that rect can be used to position the image correctly after rotation around any pivot / origin point. Caching can be optional. rot_cache = {}
def rotate_on_pivot(image: pygame.Surface, angle: float, pivot: Vector2, origin: Vector2) -> tuple[pygame.Surface, pygame.Rect]:
lookup = (image, angle)
if lookup in rot_cache:
surf = rot_cache[lookup]
else:
surf = pygame.transform.rotate(image, angle)
rot_cache[lookup] = surf
return surf, surf.get_rect(center = ((origin - pivot).rotate(-angle) + pivot)) |
Rotating an image around it's center is fairly common, it could be nice to have it as part of the transform API. If we can come to an agreement on whether this should be added or not, I've got a draft PR ready to go.
The text was updated successfully, but these errors were encountered: