有谁知道 HTML5 Canvas 是否有碰撞检测 API..?
我一直在通过编写基本思维导图应用程序来试验 HTML5 画布。我试图找出是否有任何 JavaScript API 用于管理画布中的对象,例如图像或形状之间的碰撞检测。 我认为自己编写并不是一个好主意,因为可能有一些好的 API。 任何人都有这方面的线索或一些信息。我将非常感激。
I have been experimenting HTML5 canvas by coding basic mind-mapping application. I have tried to find out if there is any javascript API used for managing object in canvas like collision detection between images or shapes.
I think it is not a good idea to write my own since there might be some good API around.
Anyone have clue or some information on this. I would very much appreciate.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
最近我自己也在尝试这个。我发现 Box2DJS 是一个很棒的牛顿物理引擎,如果你想尝试一下。 http://box2d-js.sourceforge.net/
很难理解这个概念首先,但是随着你的继续,它会变得更容易,并且它还提供了一些很好的示例。 Box2D 已被移植到多种语言,并且大多数语言都使用相同或非常相似的方法,因此任何移植的文档都可能适合您的需求。
祝你好运 :)。
编辑:我在前面提到的网站上找到了此文档的链接:http://www.kyucon。 com/doc/box2d/ (无法将其设为超链接,因为我的声誉较低,限制我每个帖子只能有一个,我是个菜鸟;P)
它适用于 Box2DFlashAS3,但他们声称“The Box2DJS API 与 Box2DFlashAS3 的 API 完全相同”
编辑:哦,我刚刚注意到你正在寻找碰撞检测,而不是物理,我的错......也许 Box2D 仍然可以工作,但也许不能。对此抱歉...
Lately I've been experimenting with this myself. I found that Box2DJS is a great Newtonian physics engine, if you want to try it out. http://box2d-js.sourceforge.net/
It's kind of hard to grasp the concept at first, but it gets easier as you go on, and it also comes with some nice examples. Box2D has been ported to many languages and most use the same, or very similar methods, so documentation for any port will likely suit your needs.
Good luck :).
EDIT: I found a link to this documentation on the previously stated site: http://www.kyucon.com/doc/box2d/ (Couldn't make it a hyper link due to my low reputation limiting me to one per post, I'm a noob ;P)
It's for Box2DFlashAS3, but they claim that "The Box2DJS APIs are completely [the] same as those of Box2DFlashAS3"
EDIT: Oh, I just noticed you were looking for collision detection, not physics, my bad... Perhaps Box2D could still work, but perhaps not. Sorry about that...
看看蛋糕。它是画布元素的场景图插件。我不认为它会进行碰撞检测,但它可能会帮助你走向正确的方向。您至少可以使用它将事件处理程序附加到画布对象。
Take a look at Cake. It's a scene graph plug-in for canvas elements. I don't think it'll do collision detection, but it will maybe help get you in the right direction. You can at least attach event handlers to canvas objects with it.
Box2DWeb 使用 Box2D.Dynamics.b2ContactListener 进行碰撞检测。
Box2DWeb 是 Box2DFlash 2.1a 的端口(因此它具有 DebugDraw 和 ContactListeners)。下面有一个调度所有联系事件的示例。
Box2DWeb has collision detection using Box2D.Dynamics.b2ContactListener.
Box2DWeb is a port of the Box2DFlash 2.1a (so it has DebugDraw and ContactListeners). There's an example below that dispatches all contact events.
看看 GameJS,它是 PyGame(著名的 Python 游戏库)的 Javascript 端口。它有精灵和精灵组的概念,并具有相当先进的碰撞检测。
Take a look at GameJS, it's a Javascript port of PyGame (well known game library for Python). It has a concept of sprites and sprite groups and has fairly advanced collision detection.