【发布时间】:2017-01-05 18:53:46
【问题描述】:
我是 PsychoPy 的新手,之前已经使用 Pygame 工作了几个月(我切换到能够在多个屏幕上呈现刺激)。
我试图弄清楚如何使用 PsychoPy 来显示使用一系列图像创建的动画。我之前在 Pygame 中实现了这一点,方法是将整个图像序列保存在一个大的 png 文件(spritesheet)中,然后每帧只翻转该图像的一部分(例如 480 x 480 像素),同时移动到下一个相同大小的下一帧中的图像部分。这大致就是我的代码在 Pygame 中的样子。我真的很想知道是否有一种在 PsychoPy 中生成动画的等效方法,方法是只选择要在每一帧中显示的图像的一部分。到目前为止,谷歌搜索还没有提供任何答案!
gameDisplay=pygame.display.set_mode((800, 480))
sequence=pygame.image.load('C:\Users\...\image_sequence.png')
#This image contains 10 images in a row which I cycle through to get an animation
image_width=480
image_height=480
start=time.time()
frame_count=0
refresh=0
while time.time()<=start+15:
gameDisplay.blit(sequence,(160,0),(frame_count*image_width,0,image_width,image_height))
if time.time()>= start+(refresh*0.25): #Flip a new image say every 250 msec
pygame.display.update()
frame_count+=1
refresh+=1
if frame_count ==10:
frame_count=0
【问题讨论】:
-
这并不能直接回答您的问题,但是如果您想要类似于支持多显示器的 pygame 的东西,我相信 pysdl2 可能适合您。它应该支持多个窗口,因为它是基于sdl2的,而pygame是基于sdl的。