使用画布模拟图层

发布于 2024-12-25 15:41:46 字数 248 浏览 2 评论 0原文

我尝试用重叠的 HTML5 画布来模拟图层,但这似乎不起作用。 HTML 中定义的第一个画布将获取所有事件,mousedown、mouseup、mousemove。

http://jsbin.com/ewival/edit#preview

是否可以用canvas模拟layeys ?这样我就可以独立使用图层/画布了?

I tried similating layers with overlapping HTML5 canvas but that doesn't appear to work. The 1st canvas defined in HTML will get all the events, mousedown, mouseup, mousemove.

http://jsbin.com/ewival/edit#preview

Is it possible to simulate layeys with canvas? So that I can work with layers/canvas independently?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

思念满溢 2025-01-01 15:41:46

最好的办法是始终将 100% 的事件处理程序保留在最顶层的画布上,并让这些事件按顺序考虑每个画布。

因此,只有一个鼠标按下等操作,它将查看您的画布列表,执行相关操作(命中检测等)。假设您的画布直接位于彼此上方,则不会出现坐标问题。

Your best bet is to always keep 100% of the event handlers on the topmost canvas, and have those events consider each canvas in order.

So there will only be one mousedown, etc, and it will look through your list of canvases doing the relevant things (hit detection, etc). Assuming your canvases are directly over each other, there will be no coordinate issues.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文