我正在使用pygame zero做一个简单的项目,到目前为止,我已经能够显示一组图像来形成一个非常简单的动画。我以每秒60fps的速度将视频渲染成.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“把它们扔到一边。
发布于 2019-01-18 18:06:48
在你的运行循环中,只需使用:只需使用clock.tick(60)#或任何你想要的fps
https://stackoverflow.com/questions/54250745
复制相似问题