使用 pygame: [spritesheet].subsurface 函数,有没有办法从底部而不是左上角绘制精灵

using the pygame: [spritesheet].subsurface function, is there a way to draw the sprite from the bottom rather than the top left corner

我有一组 sprite,也在 spritesheet 上,它略微上下弹跳,所以 sprite 高度略有变化。 通过编码:spritesheet.subsurface(x, y, width, height),会从(x, y)开始绘制精灵然后是分别向右和向下的宽度和高度,然而,当从相同的屏幕相对位置绘制帧时,精灵看起来像脚在上下移动。 因此,如果我将精灵的第 1 帧定位为让脚接触地板,则第 2 帧将使脚穿过地板。

有没有办法从左下方或底部中心绘制精灵? 非常感谢

pygame.Surface.subsurface 使用矩形区域创建一个引用其父项的新表面。 pygame坐标系的原点(0, 0)在左上角。这无法更改。

但是,如果您知道 spritsheet[=] 上 sprit 的左下坐标(left_xbottom_y) 30=] 精灵的矩形可以计算出来(spritesheet是一个pygame.Surface对象):

sheet_height = spritsheet.get_height()
sprite = spritsheet.subsurface((left_x, sheet_height - bottom_y - height, width, height))

使用 pygame.Rect 对象可以使代码更易于理解:

sheet_height = spritsheet.get_height()

sprite_rect = pygame.Rect(left_x, 0, height, height)
sprite_rect.bottom = sheet_height - bottom_y 

sprite = spritsheet.subsurface(sprite_rect )