我正在使用PyGameZero进行一个简单的项目,到目前为止,我已经能够显示一组图像来形成一个非常简单的动画。我以每秒60帧的速度将视频渲染成.png序列。看起来PyGameZero渲染它们的速度比这快一点,我只是想知道是否有一种方法可以将FPS锁定为60,这样所有的渲染都会如我所料。我有一些声音文件,我想与图像序列同步,所以让它们以恒定的FPS渲染会很有帮助。在
我还注意到声音在播放后一直循环,所以我试图在播放后停止播放,但声音在结尾处中断,因为动画似乎结束得太早。在
以下是我目前掌握的代码:
import pgzrun
WIDTH = 480
HEIGHT = 360
# boot1 graphics
boot1 = Actor('boot1_1')
boot1.frame = 1
boot1.active = True
# boot2 graphics
boot2 = Actor('boot2_1')
boot2.frame = 1
boot2.active = False
# overlay
overlay = Actor("overlay_a")
def update_boot1():
if boot1.active:
boot1.x = WIDTH/2
boot1.image = "boot1_{}".format(boot1.frame)
boot1.frame += 1
else:
boot1.x = 1000
if boot1.frame > 59:
#boot1.frame = 1
boot2.active = True
update_boot2()
boot1.active = False
def update_boot2():
if boot2.active:
boot2.x = WIDTH/2
sounds.boot1.play()
boot2.image = "boot2_{}".format(boot2.frame)
boot2.frame += 1
else:
boot2.x = 1000
if boot2.frame > 233:
boot2.frame = 233
boot2.active = False
sounds.boot1.stop()
def draw():
screen.clear
screen.fill((0, 75, 0))
boot2.draw()
boot1.draw()
overlay.draw()
# running the animation
def update(dt):
update_boot1()
update_boot2()
pgzrun.go()
我也没有找到一种方法来“卸载”图像序列,或者在我处理完它们之后使它们不可见,所以我就把它们扔到“.x=1000”的一边。在
在跑步循环中,只需使用: 就用吧时钟滴答声(60)或任何你想要的fps
相关问题 更多 >
编程相关推荐