《完美地解决了我的问题》import pygame
pygame.init()
def trim(image):
bg = pygame.Surface(image.get_size())
bg = bg.convert()
bg.fill((0,0,0))
left = image.get_width()
right = 0
top = image.get_height()
bottom = 0
image.set_colorkey((0,0,0))
for x in range(image.get_width()):
for y in range(image.get_height()):
if image.get_at((x, y)) != (0, 0, 0, 0):
left = min(x, left)
right = max(x, right)
top = min(y, top)
bottom = max(y, bottom)
width = right - left + 1
height = bottom - top + 1
return image.subsurface(pygame.Rect(left, top, width, height))
def rotate(image, angle):
return pygame.transform.rotate(trim(image), angle)
class Actor(pygame.sprite.Sprite):
def __init__(self):
pygame.sprite.Sprite.__init__(self)
self.image = pygame.image.load("fishc.png")
self.rect = self.image.get_rect()
self.rect.center = 320, 240
size = width, height = 640, 480
screen = pygame.display.set_mode(size)
fishc = Actor()
running = True
while running:
screen.fill((118, 215, 234))
screen.blit(fishc.image, fishc.rect)
fishc.image = rotate(fishc.image, 2)
for event in pygame.event.get():
if event.type == pygame.QUIT:
running = False
pygame.display.flip()
pygame.quit()
|