I am making a game in pygame and I wanted to rotate an image. pygame.transform.rotate
kept increasing the images dimensions so I thought that maybe sprites could help me to rotate an image. But the problem is more complex, I want to click somewhere on the surface and I want the image to turn into that direction, so there are infinite number of rotations the object could make. Can somebody please give me a explanation on how to do this?
相关问题
- Slick Animation - There must be one duration per f
- MultiThreading with pygame, program crashing
- Pygame for Python 3.2 on mac - import error
- Pygame Distribution - Runtime Error
- Pygame not finding image folder when in subdirecto
相关文章
- How to save captured image to disk, using Pygame
- Python pygame writing text in sprite [closed]
- Generating a Voronoi Diagram around 2D Polygons
- Pygame point image towards mouse
- How do I display a non-power-of-2-texture as sprit
- AndEngine Sprite/Box2D Body removal crashes my pro
- Glitch when moving camera in OpenGL
- Creating an accurate metronome with python and Qt
Image changing dimensions
Surfaces in pygame can't be rotated; they all have a horizontal width and a vertical height. When you load your image pygame creates a Surface which has a horizontal width and a vertical height equal to your image. When you rotate your image 45 degrees pygame have to create a new Surface where your original image fits. The new Surface's horizontal width and vertical height has to be the images hypothenuse to be able to fit the image.
This is supposed to be. If the problem you're having is about collision detection I'd recommend you to try other forms of collision detection like circular, or keep using rectangular but minimize it's size.
Rotate towards specific directions
You probably should use vectors to make the image turn to where you click. I usually create my own vector class, but pygame has its own Vector classes which should be used unless you want to create your own for learning purposes. If you don't know how add, subtract, scalar multiply, normalize and calculate angle between vectors you might want to read up on it, otherwise it might be a bit complicated. Anyway this is a small portion of a basic vector class:
Then I would do is create a class for your image with attributes position and original image. When you're rotating the image, pygame creates a new image that's rotated. By doing this your image lose some information and therefore some quality. That's why you always should rotate the original image and not a rotated copy.
A short example