Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

如何动态设置运行中滚动弹幕的移动速度 #138

Open
Ctadas opened this issue Jul 6, 2022 · 2 comments
Open

如何动态设置运行中滚动弹幕的移动速度 #138

Ctadas opened this issue Jul 6, 2022 · 2 comments

Comments

@Ctadas
Copy link

Ctadas commented Jul 6, 2022

这边有个需求是:根据视频的倍速调整弹幕的速度。我调整CommentManager的options.global.scale,未出现的弹幕可以满足效果,但是在runline的弹幕不受这个参数的影响,我尝试直接修改runline弹幕的ttl和dur也没有效果,我需要怎么设置才能调整runline的弹幕的速度一致?

@jabbany
Copy link
Owner

jabbany commented Jul 6, 2022

直接修改runline弹幕的ttl和dur

确实这样实现。。。不过CSS弹幕有一些特殊的坑,因为不是靠CommentManager驱动,所以需要多 call 一下 cmt.stop() 来收动删掉旧的CSS,这样下一个tick就能补回来。

目前版本上,实现此效果的样本代码,可在demo → code里面测试运行:

// 弹幕速度降低到原来的 1/4
cm.options.global.scale *= 4;
cm.runline.forEach(function (cmt) {
   cmt.ttl *= 4;
   cmt.dur *= 4;
   cmt.stop(); // 这个有点hack
});

不过这个应该算是 API 实现的 bug,CssComment.ts 里面应该覆盖 ttl 和 dur 的 setter 来自动刷掉旧的 css。

TODO 需要fix如下:

  • 把 CssComment.stop 方法内的码挪到 invalidate 里面,让 stop 调用 invalidate
  • 覆盖 ttl 和 dur的 setter方法,设定参数后调用 invalidate 刷掉 css

修复后直接设 ttl / dur 就应该够了

@dbFlower
Copy link
Contributor

dbFlower commented Jul 6, 2022 via email

@jabbany jabbany added the bug label Jul 6, 2022
@jabbany jabbany added this to the Move to TypeScript Entirely milestone Jul 7, 2022
@jabbany jabbany closed this as completed Jul 26, 2023
@jabbany jabbany reopened this Jul 26, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

3 participants