Skip to content
Discussion options

You must be logged in to vote

我使用的弹幕渲染库是这个
https://github.com/weizhenye/Danmaku
具体的实现细节可以去那里咨询

关于弹幕位置的计算方式在这里
https://github.com/weizhenye/Danmaku/blob/master/src/engine/index.js

我这里可以概况一下

弹幕位置由两个参数决定:

  1. 弹幕开始时间 cmtt
  2. 弹幕划过屏幕的所需时间 duration(即屏幕宽度/速度)

怎么得到弹幕的结束时间和具体的滚动位置

首先计算弹幕行走的总长度 = 屏幕宽度 + 弹幕长度 = totalWidth
然后计算弹幕走完的比例 = (当前视频时间 - cmtt) / duration = elapsed

当前帧的弹幕位置 = totalWidth * elasped

每帧计算一次

当前时间 - cmtt > duration 这条弹幕就算结束了

怎么让长度不同的弹幕速度还有些不同

由于 duration 是固定的,那么越长的弹幕必然会比短的弹幕更快的划过屏幕

Replies: 1 comment 1 reply

Comment options

You must be logged in to vote
1 reply
@MiKoto-Railgun
Comment options

Answer selected by MiKoto-Railgun
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants