Pygame 获取滚动坐标

Pygame get scroll coordinates

有什么方法可以得到pygame表面"scroll"函数的坐标吗? 例如

image.scroll(0,32)
scroll_coords = image.??? ### scroll_coords should be (0,32)

您可以只将滚动坐标存储在向量、列表或矩形中,并且每当您滚动表面时,也更新向量。 (按 w 或 s 滚动表面)

import sys
import pygame as pg


def main():
    clock = pg.time.Clock()
    screen = pg.display.set_mode((640, 480))

    image = pg.Surface((300, 300))
    image.fill((20, 100, 90))
    for i in range(10):
        pg.draw.rect(image, (160, 190, 120), (40*i, 30*i, 30, 30))

    scroll_coords = pg.math.Vector2(0, 0)

    done = False

    while not done:
        for event in pg.event.get():
            if event.type == pg.QUIT:
                done = True
            if event.type == pg.KEYDOWN:
                if event.key == pg.K_w:
                    scroll_coords.y -= 10
                    image.scroll(0, -10)
                elif event.key == pg.K_s:
                    scroll_coords.y += 10
                    image.scroll(0, 10)
                print(scroll_coords)

        screen.fill((50, 50, 50))
        screen.blit(image, (100, 100))

        pg.display.flip()
        clock.tick(30)


if __name__ == '__main__':
    pg.init()
    main()
    pg.quit()
    sys.exit()