2017-05-05 18 views
1

pygameサーフェスの "scroll"関数の座標を取得する方法はありますか?例: Pygameスクロール座標を取得

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

答えて

0

ベクトル、リストまたは矩形にスクロール座標を格納するだけで、サーフェスをスクロールするときにもベクトルを更新できます。 (表面をスクロールするには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() 
関連する問題