Reputation: 263
I am new to pygame and python itself. But right now, i have to make a spinner. It should stop at random times. What i was thinking was that i can have random.randint(0, 360). So i can make it stop at random times. But right now, I can only make it rotate 90, or else it moves of the screen.
Any help would be useful.
Thanks
import sys, pygame, time
pygame.init()
screen = pygame.display.set_mode([600,600])
black = 255,255,0
ball = pygame.image.load("wheel.gif")
temp = pygame.image.load("wheel.gif")
ballrec = ball.get_rect().center
while 1:
for event in pygame.event.get():
if event.type == pygame.QUIT:
sys.exit()
screen.fill(black)
ball = pygame.transform.rotate(ball, 45)
ballrec = ball.get_rect().center
screen.blit(ball, ballrec)
pygame.display.flip()
time.sleep(1)
Upvotes: 2
Views: 2062
Reputation: 72745
I've noticed that if you keep rotate the rotated object repeatedly, as you're doing in ball = pygame.transform.rotate(ball, 45)
, the sprite gets distorted and starts to move off screen. I usually keep the original image and switch back to that when I rotate 360 degrees.
Upvotes: 1
Reputation: 47072
As noted here, rotating by angles that are not divisible by 90 requires the image being padded. You should be able to just blit the image to always be centered at 128,128 or you can trim off the edges of the image as necessary.
Upvotes: 0