Lottie Web:同时在同一画布中播放2个动画
我是洛蒂(Lottie)的新手,想知道如何在网络上的同一帆布元素中同时播放2个动画。
我遵循了这个示例[1],然后在此处给出的建议[2]分别在每个框架上转换画布以分别定位一个动画。
我想实现的是:2个红球并排在同一画布上弹跳。一个在x = 0的比赛中,一个在同一画布上播放x = 100。
这是我在Codepen [3]中的方法。我提取了JS以获得可见性。
const testjson = {...animation...};
const cvs = document.getElementById("canvas");
const ctx = cvs.getContext("2d");
// Drawing sth on the context to see whether sharing works
ctx.fillStyle = "green";
ctx.fillRect(0, 0, 40, 40);
function renderAnimation(canvasContext, translation) {
const animData = {
renderer: "canvas",
loop: true,
rendererSettings: {
context: canvasContext,
clearCanvas: true,
},
animationData: testjson,
};
const anim = bodymovin.loadAnimation(animData);
// Transform the canvas for the respective animation on enter-frame
anim.addEventListener("enterFrame", () => {
ctx.translate(translation.x, translation.y);
});
// If efective, causes onion-effect
// anim.setSubframe(false);
}
renderAnimation(ctx, { x: 0, y: 0 });
renderAnimation(ctx, { x: 100, y: 0 });
las,我实施的方式似乎不起作用。 有人知道我缺少什么吗?
谢谢你!
[1]: https://codepen.io/RenanSgorlom/pen/orgxyJ
[2]: https://github.com/airbnb/lottie-web/issues/1671
[3]: https://codepen.io/user1207504/pen/MWVYvxd
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您不需要太多代码就可以在同一画布上弹跳一些球...
当然,图书馆无需这样做。
我们可以使用
arc
函数绘制的球:x += vx
vx *= -1
中You don't need that much code to have some balls bouncing on the same canvas ...
Certainly no need for a library to just do that.
The balls we can draw using
arc
functions:https://developer.mozilla.org/en-US/docs/Web/API/CanvasRenderingContext2D/arc
x += vx
vx *= -1