1
파이 게임 표면의 "스크롤"기능의 좌표를 가져 오는 방법이 있습니까? 예 :파이 게임이 스크롤 좌표를 얻습니다
image.scroll(0,32)
scroll_coords = image.??? ### scroll_coords should be (0,32)
파이 게임 표면의 "스크롤"기능의 좌표를 가져 오는 방법이 있습니까? 예 :파이 게임이 스크롤 좌표를 얻습니다
image.scroll(0,32)
scroll_coords = image.??? ### scroll_coords should be (0,32)
당신은 벡터, 목록 또는 RECT에 스크롤 좌표를 저장하고 당신이 표면을 스크롤 할 때마다,뿐만 아니라 벡터를 업데이트 할 수 있습니다. (표면을 스크롤하려면 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()