だから私はこのコードを持っています、そしてそれはそれがうまくいくはずのことをします。私がやりたいのは、正方形をさまざまな量でランダムにスケーリングすることです。私の問題はblit関数にあります。blitは古い形状を削除せず、新しい形状をサーフェスにコピーするだけなので、正方形は拡大しているように見えます。
単に拡大するだけでなく、形状を拡大および縮小するにはどうすればよいですか?
私のコード:
import sys, random, pygame
from pygame.locals import *
pygame.init()
w = 640
h = 480
screen = pygame.display.set_mode((w,h))
morphingShape = pygame.Surface((20,20))
morphingShape.fill((255, 137, 0)) #random colour for testing
morphingRect = morphingShape.get_rect()
def ShapeSizeChange(shape, screen):
    x = random.randint(-21, 20)
    w = shape.get_width()
    h = shape.get_height()
    if w + x > 0 and h + x > 0:
        shape = pygame.transform.smoothscale(shape, (w + x, h + x))
    else:
        shape = pygame.transform.smoothscale(shape, (w - x, h - x))
    shape.fill((255, 137, 0))
    rect = shape.get_rect()
    screen.blit(shape, rect)
    return shape
while True:
    for event in pygame.event.get():
        if event.type == pygame.QUIT:
            pygame.quit()
            sys.exit()
    morphingShape = ShapeSizeChange(morphingShape, screen)
    pygame.display.update()