询问一下弹幕移动的位置是怎么计算的 #62
Answered
by
Mr-Quin
MiKoto-Railgun
asked this question in
Q&A
-
|
如题,就是想询问一下滚动弹幕的位置是怎么计算的?弹弹play接口返回的数据格式是json格式的字符串,弹幕只有开始时间可用,我想知道大佬是怎么得到弹幕的结束时间和具体的滚动位置,且让长度不同的弹幕速度还有些不同的? |
Beta Was this translation helpful? Give feedback.
Answered by
Mr-Quin
Feb 3, 2025
Replies: 1 comment 1 reply
-
|
我使用的弹幕渲染库是这个 关于弹幕位置的计算方式在这里 我这里可以概况一下 弹幕位置由两个参数决定:
首先计算弹幕行走的总长度 = 屏幕宽度 + 弹幕长度 = 当前帧的弹幕位置 = 每帧计算一次 当前时间 -
由于 |
Beta Was this translation helpful? Give feedback.
1 reply
Answer selected by
MiKoto-Railgun
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
我使用的弹幕渲染库是这个
https://github.com/weizhenye/Danmaku
具体的实现细节可以去那里咨询
关于弹幕位置的计算方式在这里
https://github.com/weizhenye/Danmaku/blob/master/src/engine/index.js
我这里可以概况一下
弹幕位置由两个参数决定:
cmttduration(即屏幕宽度/速度)首先计算弹幕行走的总长度 = 屏幕宽度 + 弹幕长度 =
totalWidth然后计算弹幕走完的比例 = (当前视频时间 -
cmtt) /duration=elapsed当前帧的弹幕位置 =
totalWidth * elasped每帧计算一次
当前时间 -
cmtt>duration这条弹幕就算结束了由于
duration是固定的,那么越长的弹幕必然会比短的弹幕更快的划过屏幕