【发布时间】:2019-01-18 09:13:27
【问题描述】:
我正在使用 pygame zero 进行一个简单的项目,到目前为止,我已经能够显示一组图像来形成一个非常简单的动画。我以 60 fps 的速度将视频渲染成 .png 序列。看起来 pygame zero 渲染它们的速度比这快一点,我只是想知道是否有办法将 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”把它们扔到一边。
【问题讨论】:
标签: python python-3.x raspberry-pi pygame