【发布时间】:2021-01-29 15:06:43
【问题描述】:
我想创建一个游戏,其中圆圈在表面上随机生成并开始增长。当两个圆圈相互接触时,游戏结束。所以,除了在循环期间调整精灵的大小之外,一切都在工作。当我使用transform.scale 时,我会得到这样的结果:
然后我在文档中找到了transform.smoothscale。我使用更改了我的代码来使用它,然后它看起来像这样:
我也尝试使用Rect.inflate,但这对我的精灵没有任何作用。我尝试了Rect.infalte_ip,如果我使用它,精灵不会长大,它更有可能移出框架。有什么想法可以让这些 Sprite 在适当的位置生长并调整它们的大小吗?
class Bubbles(pygame.sprite.Sprite):
def __init__(self):
super().__init__()
self.image_scale = 100
self.image_scale_factor = 1
self.image = resources.BUBBLE_SKIN[0].convert_alpha()
self.image = pygame.transform.scale(self.image, (self.image_scale, self.image_scale))
self.rect = self.image.get_rect()
self.rect.centerx = (random.randrange(Settings.object_range_limit + (self.image_scale//2), (Settings.width - Settings.object_range_limit - self.image_scale)))
self.rect.centery = (random.randrange(Settings.object_range_limit + (self.image_scale//2), (Settings.height - Settings.object_range_limit - self.image_scale)))
self.growth_rate = random.randint(1, 4)
def update(self):
self.image_scale += self.growth_rate
self.image = pygame.transform.scale(self.image, (self.image_scale, self.image_scale))
【问题讨论】:
-
你是在缩放原始精灵还是逐渐缩放精灵?
-
请出示一些代码以便我们为您提供帮助
-
我将精灵的图像保存在“self.image”中。我用这个变量来缩放图像。
-
你是否经常使用
self.image= pygame.trasnform.smoothscale(self.image, ...)`之类的东西?
标签: python pygame pygame-surface